gpt4 book ai didi

javascript - 处理付款

转载 作者:行者123 更新时间:2023-11-30 16:55:50 28 4
gpt4 key购买 nike

我有一个困境,相当大。

我正在使用 stripe 作为我的支付网关,它以两种方式工作。

  1. 收集生成 token 的账单信息
  2. 使用 token 向客户收费

问题是 token 只能使用一次,在第 1 步我无法验证客户是否有足够的资金,所以如果没有,那么卡就会被拒绝,问题是我无法重复使用 token ,所以我不能回到客户那里,再次询问他们的详细信息。所以我的问题是如何在不向客户收费的情况下验证他们在生成 token 时是否有足够的资金。

下面是如何生成代码的快速浏览:

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 documentation :

account_balance integer

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.

您需要检索 customer 对象 并检查 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

关于javascript - 处理付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29739349/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com