简体   繁体   English

付款工作

[英]Working with payment

I have a dilema, quite a big one. 我有一个难题,很大。

I am working stripe as my payment gateway and it works in a 2 way process. 我正在将Stripe作为我的付款网关,它以2种方式工作。

  1. Collect billing info which generated a token 收集生成令牌的账单信息
  2. charge the client using token 使用令牌向客户收费

problem is that token can only be used once and on step 1 i am unable to verify if client has sufficient fund, so if it doesn't then the card gets declined, and the problem is that i can't reused the token so i cant go back to the customer, and ask for their details again. 问题是令牌只能使用一次,而在步骤1上,我无法验证客户是否有足够的资金,所以如果没有,则卡会被拒绝,问题是我无法重复使用令牌,所以我无法回头给客户,并再次询问他们的详细信息。 So my question is how to i verify without charging the client that they have sufficient fund when generating the token. 所以我的问题是如何在生成令牌时不向客户收取他们有足够资金的情况下进行验证。

below is a quick look on how the code is generated: 以下是代码生成的快速查看:

function onSubmit() {
    var $form = $('#payment-form'); // TODO: give your html-form-tag an "id" attribute and type this id in this line. IMPORTANT: Don't replace the '#'!

    // Disable the submit button to prevent repeated clicks
  // TODO: give your html-submit-input-tag an "id" attribute

    Stripe.card.createToken($form, stripeResponseHandler);
}

update: 更新:

   // This identifies your website in the createToken call below
  Stripe.setPublishableKey('CODE');

    var appendedStripeToken = false;

var stripeResponseHandler = function(status, response) {
    var $form = $('#payment-form');

    if (response.error) {
        // Show the errors on the form
        $form.find('.payment-errors').text(response.error.message);
                $form.find('button').prop('disabled', false);

    } else {
        // token contains id, last4, and card type
        var token = response.id;
        handleCall(token);
    }
};

function handleCall(token) { 
   var $form = $('#payment-form');
    if (!appendedStripeToken) { 
        // Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" id="courseToken" name="stripeToken" />').val(token));
        appendedStripeToken = true; 
        phpCall(); 

    } 
}

function onSubmit() {
    var $form = $('#payment-form'); // TODO: give your html-form-tag an "id" attribute and type this id in this line. IMPORTANT: Don't replace the '#'!

    // Disable the submit button to prevent repeated clicks
  // TODO: give your html-submit-input-tag an "id" attribute

    Stripe.card.createToken($form, stripeResponseHandler);
}


function phpCall() {
 if( appendedStripeToken === true ){
   $.ajax({
    type: "POST",
    data: {run: true, priceFinal: $('#priceFinal').val(), courseProvider: $('#courseProvider').val(), 
    userEmail: $('#userEmail').val(), courseDelivery: $('#courseDelivery').val(), courseTitle: $('#courseTitle').val(), courseDate: $('#courseDate').val(), 
    courseToken: $('#courseToken').val(), cardname: $('#billingcardName').val(), finalCoupon: $('#finalCoupon').val(), couponDiscount: $('#couponDiscount').val() },
    url: 'functions/paymentEmail.php',
    success: function (response) {//response is value returned from php (for    your example it's "bye bye"
                  $('#payment-form').prop('disabled', true); // TODO: give your html-submit-input-tag an "id" attribute

window.location = response;
    }
   });
 }
} 

From stripe-payments api documentation : 从stripe-payments api文档中

account_balance integer account_balance整数

Current balance, if any, being stored on the customer's account. 当前余额(如果有)存储在客户帐户中。 If negative, the customer has credit to apply to the next invoice. 如果为负,则客户有信用额度可以申请下一张发票。 If positive, the customer has an amount owed that will be added to the next invoice. 如果为正,则客户的欠款金额将被添加到下一张发票中。 The balance does not refer to any unpaid invoices; 余额不涉及任何未付发票; it solely takes into account amounts that have yet to be successfully applied to any invoice. 它仅考虑尚未成功应用于任何发票的金额。 This balance is only taken into account for recurring charges. 此余额仅用于经常性费用。

You need to retrieve the customer object and check the balance element. 您需要检索customer object并检查balance元素。

Request Endpoint: 请求端点:

POST https://api.stripe.com/v1/customers

Example Request: 请求示例:

curl https://api.stripe.com/v1/customers \
   -u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
   -d description="Customer for test@example.com" \
   -d source=tok_15tOII2eZvKYlo2CIU6PJLtY

Example Response: 示例响应:

Stripe\Customer JSON: {
  "object": "customer",
  "created": 1429505322,
  "id": "cus_65iGlrQ2E95Vct",
  "livemode": false,
  "description": null,
  "email": "tet@test.com",
  "delinquent": false,
  "metadata": {
  },
  "subscriptions": {
    "object": "list",
    "total_count": 0,
    "has_more": false,
    "url": "/v1/customers/cus_65iGlrQ2E95Vct/subscriptions",
    "data": [

    ]
  },
  "discount": null,
  "account_balance": 0,
   etc...

This is what you need: 这是您需要的:

"account_balance": 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM