2015-04-20 157 views
1

我有一個困境,相當大的一個。使用付款

我工作條紋作爲我的支付網關,它工作在2方式的過程。其生成的令牌

  • 充電使用令牌
  • 問題客戶

    1. 收集帳單信息是令牌只能使用一次,並在第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; 
          } 
          }); 
      } 
      } 
      
    +0

    不能收取用戶,如果他/她沒有足夠的平衡,所以,付款將是要麼是成功或失敗,如果失敗,有重新啓動事務新的令牌。 –

    +0

    但我如何驗證他們是否有足夠的餘額而不收取費用?它很尷尬詢問客戶他們的信用卡細節 – John

    回答

    2

    從條紋支付api documentation

    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 [email protected]" \ 
        -d source=tok_15tOII2eZvKYlo2CIU6PJLtY 
    

    實施例響應:

    Stripe\Customer JSON: { 
        "object": "customer", 
        "created": 1429505322, 
        "id": "cus_65iGlrQ2E95Vct", 
        "livemode": false, 
        "description": null, 
        "email": "[email protected]", 
        "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 
    
    +0

    感謝您的迴應。你能詳細解釋一下嗎? – John

    +0

    我已經更新了我的回答,所以很清楚。 –

    +0

    謝謝。我仍然試圖讓我的前景圍繞它。如何驗證客戶是否有足夠的餘額而不收取費用 – John