簡體   English   中英

付款工作

[英]Working with payment

我有一個難題,很大。

我正在將Stripe作為我的付款網關,它以2種方式工作。

  1. 收集生成令牌的賬單信息
  2. 使用令牌向客戶收費

問題是令牌只能使用一次,而在步驟1上,我無法驗證客戶是否有足夠的資金,所以如果沒有,則卡會被拒絕,問題是我無法重復使用令牌,所以我無法回頭給客戶,並再次詢問他們的詳細信息。 所以我的問題是如何在生成令牌時不向客戶收取他們有足夠資金的情況下進行驗證。

以下是代碼生成的快速查看:

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);
}

更新:

   // 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;
    }
   });
 }
} 

從stripe-payments api文檔中

account_balance整數

當前余額(如果有)存儲在客戶帳戶中。 如果為負,則客戶有信用額度可以申請下一張發票。 如果為正,則客戶的欠款金額將被添加到下一張發票中。 余額不涉及任何未付發票; 它僅考慮尚未成功應用於任何發票的金額。 此余額僅用於經常性費用。

您需要檢索customer object並檢查balance元素。

請求端點:

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

請求示例:

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

示例響應:

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...

這是您需要的:

"account_balance": 0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM