stripe 支付

stripe 支付整理
1、创建账号
官方网址 中文版 https://stripe.com/zh-cn-us/payments
2、激活你的账号
在这里插入图片描述
填写信息只支持国外与香港的哦
在这里插入图片描述

在这里插入图片描述

3、开发者秘钥
如果不激活的话,只能用测试api秘钥在这里插入图片描述

4、配置你的回调地址
配置秘钥,选择webhook事件
事件一定要选择 checkout 与change
在这里插入图片描述
5、设置支付方式
获取支付方式资格,没有资格的付款方式,是不可以用来支付的,一定要注意
在这里插入图片描述
6、官方实例
官方文档 https://stripe.com/docs/payments/integration-builder
官方实例:不同语言的都有
记得用之前先安装一下扩展 composer require stripe/stripe-php
在这里插入图片描述
支付宝支付文档
https://stripe.com/docs/payments/alipay/accept-a-payment
在这里插入图片描述
微信支付文档
https://stripe.com/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.com/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.com/docs/testing 在这里插入图片描述
9、付款后操作
根据自己需求,对应官方文档进行自己编写
https://stripe.com/docs/payments/after-the-payment在这里插入图片描述

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值