使用付款

时间:2015-04-20 04:28:43

标签: javascript php jquery html stripe-payments

我有一个相当大的困境。

我正在使用条纹作为我的支付网关,它可以双向处理。

  1. 收集生成令牌的结算信息
  2. 使用令牌
  3. 向客户收费

    问题是令牌只能使用一次而且在第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;
        }
       });
     }
    } 
    

1 个答案:

答案 0 :(得分:2)

来自条约付款api documentation

  

account_balance integer

     

当前余额(如果有)存储在客户的帐户中。如果   否定,客户有信用申请下一张发票。如果   积极的,客户有欠款将被添加到   下一张发票。余额不是指任何未付的发票;它   仅考虑尚未成功的金额   适用于任何发票。这种平衡只被考虑在内   经常性费用。

您需要检索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