如何向用户添加卡并使用Stripe进行充电
How to add a card to a user and charge it using Stripe?
我有一个页面,用户在其中输入cc并收取费用。
我使用js 创建一个卡令牌
Stripe.card.createToken(ccData, function stripeResponseHandler(status, response) {
var token = response.id;
// add the cc info to the user using
// charge the cc for an amount
});
要添加cc,我正在使用php
$stripeResp = Stripe_Customer::retrieve($stripeUserId);
$stripeResp->sources->create(['source' => $cardToken]);
为了给cc充电,我使用php以及
$stripeCharge = Stripe_Charge::create([
'source' => $token,
'amount' => $amount
]);
做了所有这些,我得到了You cannot use a Stripe token more than once
。
有什么想法吗?我可以把抄送保存给这个用户$stripeUserId
并充电。
PHP是受欢迎的,但js也很棒。
https://stripe.com/docs/tutorials/charges
保存信用卡详细信息以备日后使用
条纹代币只能使用一次,但这并不意味着你必须要求您的客户每次付款的卡详细信息。条纹提供了一个Customer对象类型,使保存该对象变得容易--并且其他——供以后使用的信息。
创建一个新客户,而不是立即向卡收费,在该过程中将令牌保存在Customer上。这会让你在未来的任何时候向客户收费:
(以下是多种语言的示例)。PHP版本:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
'Stripe'Stripe::setApiKey("yourkey");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create a Customer
$customer = 'Stripe'Customer::create(array(
"source" => $token,
"description" => "Example customer")
);
// Charge the Customer instead of the card
'Stripe'Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "usd",
"customer" => $customer->id)
);
// YOUR CODE: Save the customer ID and other info in a database for later!
// YOUR CODE: When it's time to charge the customer again, retrieve the customer ID!
'Stripe'Charge::create(array(
"amount" => 1500, // $15.00 this time
"currency" => "usd",
"customer" => $customerId // Previously stored, then retrieved
));
在Stripe中使用存储的支付方式创建客户后,您可以在任何时间点通过路过客户向该客户收费收费请求中的ID,而不是卡片表示。要确定将客户ID存储在您的一侧以备日后使用。
更多信息,请访问https://stripe.com/docs/api#create_charge-客户
Stripe有优秀的文档,请阅读!
相关文章:
- 从远程脚本获取用户IP
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- d3基于用户选择动态更新节点
- 同步调用,直到用户通过angular验证为访问者
- 使用javascript搜索具有用户输入的数组
- 如何使用jquery确定用户是否年满18岁
- Meteor-添加用户自定义字段的方法不起作用
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- 跟踪用户点击Adsense广告的IP地址
- 使用javascript反复检查用户在facebook上的登录状态
- 我想在AngularJS应用程序中创建一个输入数字框,用户不应该在该框上键入十进制数字.(一个整数输入框)
- 如何检查用户在html5视频播放器中观看了完整的视频
- 一个密码测试程序,如果存在空格,它会提醒用户
- 如何使用JavaScript中的用户输入创建序列/序列
- 通过 Stripe 向用户收费,并将资金存入另一个用户帐户
- 如何向用户添加卡并使用Stripe进行充电
- 如何使用stripe创建用户银行账户?
- React Native:一个Stripe用户如何向另一个Stripe用户发送支付
- 如何在用户内容刷新前使用stripe api检查卡数下降
- 为用户更新Stripe上的主信用卡