[英]Working with payment
我有一个难题,很大。
我正在将Stripe作为我的付款网关,它以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.