java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

海外支付stripe对接支付

strip支付

https://stripe.com/docs/checkout/tutorial

测试的信用卡号
4242424242424242

各种测试的信用卡
https://stripe.com/docs/testing#international-cards

注意填写日期的时候,尽管可以随便写,但是你不能写年份低于当前的,比如15 就不行。我写19就可以了 2019年到期 2015年到期,就不行了,说明卡过期了。

strip

返回的数据,采用POST方式

array(3) { ["stripeToken"]=> string(28) "tok_19xSp5GoFgQiAmhVvbVsCIGI" ["stripeTokenType"]=> string(4) "card" ["stripeEmail"]=> string(15) "asdasdf@afd.com" } 

stripeToken 这个估计是拿来验证支付信息是否正确的。

如何使用

With Stripe, sensitive cardholder data does not hit your server, greatly minimizing your PCI compliance burden. Stripe takes care of the hardest parts of PCI compliance, like redacting logs and encrypting card details. Just enable HTTPS on your checkout page, and we'll take over from there.

在strip里,持卡人的敏感数据不会发送到你的服务器,最大限度的减少您程序接口的负担,Stripe负责最复杂的部分,比如日志处理,信用卡数据加密等服务器。只要您开启HTTPS服务器,我们就会接管这些事务。

Checkout, running in the browser, securely accepts the payment information but does not initiate a payment attempt. The actual charge request is triggered from your server.

结账,安全地运行在浏览器中,接受支付信息但不启动尝试付款。实际的费用从您的服务器请求触发。

就是说JS的触发了一个POST,但是并没有启动付款动作,你的接受的action的php后台,才会触发付款动作。

你需要转到这个文档里来。
https://stripe.com/docs/charges

当然代码支持的类库很全面
curl Ruby Python PHP Java Node Go

月小升这里用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("sk_test_0DStyoqg2BHbmxQ6X0C6uNIv");

// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
$token = $_POST['stripeToken'];

// Charge the user's card:
$charge = \Stripe\Charge::create(array(
  "amount" => 1000,
  "currency" => "usd",
  "description" => "Example charge",
  "source" => $token,
));

php类包下载地址

https://github.com/stripe/stripe-php/releases

key

//有数据返回
if($_POST['stripeToken']){
  var_dump($_POST);
  // 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("sk_test_0DStyoqg2BHbmxQ6X0C6uNIv");

    // Token is created using Stripe.js or Checkout!
    // Get the payment token submitted by the form:
    $token = $_POST['stripeToken'];

    // Charge the user's card:
    $charge = \Stripe\Charge::create(array(
      "amount" => 999,
      "currency" => "usd",
      "description" => "Example charge",
      "source" => $token,
    ));


    echo $charge;

}

https://dashboard.stripe.com/account/apikeys

里面有个Secret Key 还有个Publishable Key 一个是私钥,一个是公钥

私钥在后端的php文件里,公钥在前端的JS里。

返回的信息是个JSON

Stripe\Charge JSON: {

"id": "ch_19xWEzGoFgQiAmhVCHyf4QXV",

"object": "charge",

"amount": 999,

"amount_refunded": 0,

"application": null,

"application_fee": null,

"balance_transaction": "txn_19xWEzGoFgQiAmhVx5i632K2",

"captured": true,

"created": 1489561693,

"currency": "usd",

"customer": null,

"description": "Example charge",

"destination": null,

"dispute": null,

"failure_code": null,

"failure_message": null,

"fraud_details": [



],

"invoice": null,

"livemode": false,

"metadata": [



],

"on_behalf_of": null,

"order": null,

"outcome": {

"network_status": "approved_by_network",

"reason": null,

"risk_level": "normal",

"seller_message": "Payment complete.",

"type": "authorized"

},

"paid": true,

"receipt_email": null,

"receipt_number": null,

"refunded": false,

"refunds": {

"object": "list",

"data": [



],

"has_more": false,

"total_count": 0,

"url": "\/v1\/charges\/ch_19xWEzGoFgQiAmhVCHyf4QXV\/refunds"

},

"review": null,

"shipping": null,

"source": {

"id": "card_19xW8mGoFgQiAmhVR7RLukQj",

"object": "card",

"address_city": null,

"address_country": null,

"address_line1": null,

"address_line1_check": null,

"address_line2": null,

"address_state": null,

"address_zip": null,

"address_zip_check": null,

"brand": "Visa",

"country": "US",

"customer": null,

"cvc_check": "pass",

"dynamic_last4": null,

"exp_month": 10,

"exp_year": 2018,

"fingerprint": "GEqiXsC33FyB3ZKH",

"funding": "credit",

"last4": "4242",

"metadata": [



],

"name": "asdfsadf@asfd.com",

"tokenization_method": null

},

"source_transfer": null,

"statement_descriptor": null,

"status": "succeeded",

"transfer_group": null

}

接下来我们检查status 为 succeeded,然后才用返回的付款信息,进行验证自己订单的金额这些数据是否一致,就可以給网站返回是否成功的信息了。

基本打通了。


This entry was posted in PHP and tagged , , , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/pay-for-stripe/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

3 Responses to 海外支付stripe对接支付

  1. says:

    我想获取 data-amount 值,也就是到后台的时候amount的值是前台传过来的,怎么获取,
    我这样获取 $amount = $_POST[‘data-amount’], 获取不到值,为什么?

Leave a Reply