stripe 支付整理
1、创建账号
官方网址 中文版 https://stripe/zh-cn-us/payments
2、激活你的账号
填写信息只支持国外与香港的哦
3、开发者秘钥
如果不激活的话,只能用测试api秘钥
4、配置你的回调地址
配置秘钥,选择webhook事件
事件一定要选择 checkout 与change
5、设置支付方式
获取支付方式资格,没有资格的付款方式,是不可以用来支付的,一定要注意
6、官方实例
官方文档 https://stripe/docs/payments/integration-builder
官方实例:不同语言的都有
记得用之前先安装一下扩展 composer require stripe/stripe-php
支付宝支付文档
https://stripe/docs/payments/alipay/accept-a-payment
微信支付文档
https://stripe/docs/sources/wechat-pay
Apple pay 文档
7、简单的代码开发
require 'vendor/autoload.php';
//信用卡支付方法
public function pay($token, $amount, $order_sn)
{
$amount = bcmul($amount,100);//支付没有分需要*100
\Stripe\Stripe::setApiKey('你的开发密钥');//在开发者 api秘钥里查找 不是发布秘钥,发布秘钥是前端使用的
$amount = floatval($amount);
$charge = \Stripe\Charge::create([
// 'payment_method_types' => ['alipay'],
'amount' => $amount,//金额 实际支付金额 需要*100,不支持小数点
'currency' => 'usd',//币种 根据你自己的项目选择支付的币种
'description' => $order_sn,//描述
'source' => $token,//用户token 前端吊调起支付时 获取
]);
return $charge;
}
//支付宝支付
public function alipay_pay($amount,$order_sn)
{
$amount = bcmul($amount,100);//支付没有分需要*100
\Stripe\Stripe::setApiKey('你的开发密钥');//在开发者 api秘钥里查找 不是发布秘钥,发布秘钥是前端使用的
$amount = floatval($amount);
$charge = \Stripe\PaymentIntent::create([
'payment_method_types' => ['alipay'],
'amount' => $amount,//金额
'currency' => 'AUD',//币种
'description' => $order_sn,//描述
]);
return $charge;//将此值中的client_secret给前端,由前端调起支付宝支付
}
//微信支付 $source 前端调微信获取的资源
public function wxpay_pay($source,$amount,$order_sn)
{
$amount = bcmul($amount,100);//支付没有分需要*100
\Stripe\Stripe::setApiKey('你的开发密钥');//在开发者 api秘钥里查找 不是发布秘钥,发布秘钥是前端使用的
$amount = floatval($amount);
$charge = \Stripe\Charge::create([
'amount' => $amount,
'currency' => 'AUD',//币种
'source' => $source,
'description' => $order_sn,//描述
]);
return $charge;
}
// apple pay 支付 //将此值中的client_secret给前端,由前端调起apple 支付 ,前端可能还需要配置支付证书哦
public function apple_pay($amount,$order_sn)
{
$amount = bcmul($amount,100);//支付没有分需要*100
\Stripe\Stripe::setApiKey($this->sk_key);
$amount = floatval($amount);
$charge = \Stripe\PaymentIntent::create([
'amount' => $amount,
'currency' => 'aud',//币种
'description' => $order_sn,//描述
]);
return $charge;
}
/**
* Notes:退款
*/
public function refund($refund_id,$amount){
$amount = bcmul($amount,100); //实际退款金额没有小数点,在返回的数据里面减去
$amount = floatval($amount);
// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe/account/apikeys
\Stripe\Stripe::setApiKey('你的开发密钥');//在开发者 api秘钥里查找 不是发布秘钥,发布秘钥是前端使用的
$refund = \Stripe\Refund::create([
'charge' => $refund_id,// 并提供要退款的ID。也就是你支付回调里面的id
'amount' => $amount,//部分退款金额 不填写则是全部退款
]);
return $refund;
}
/**
* Notes:stripe 支付回调
*/
function stripe_callback()
{
$data = input('param.');
if (empty($data) ) {
echo "error";
die;
}
$object = $data['data']['object'];
if(!$object){
echo "error";
die;
}
$amount = bcdiv($object['amount'],100);//实际金额需要除以100 才是你的支付金额
//TODO::stripe 业务逻辑处理
echo "success";
die;
}
8、附加测试数据
测试账号资料:https://stripe/docs/testing
9、付款后操作
根据自己需求,对应官方文档进行自己编写
https://stripe/docs/payments/after-the-payment
更多推荐
stripe 支付
发布评论