Stripe alipay wechat_pay 创建支付接口

#composer require stripe/stripe-php

<?php
require_once('vendor/autoload.php');

$skapi='sk_live_KEY';
$stripe = new  \Stripe\StripeClient($skapi);

//wechat_pay和 alipay 二选一
//$Methodtype = 'wechat_pay';
$Methodtype = 'alipay';

$paymentMethod = $stripe->paymentMethods->create(['type' => $Methodtype]);

$paymentIntentParams = [
    'amount' => 1000,  // 金额,单位为最小货币单位(1000 为 10 元人民币)
    'currency' => 'cny',
    'payment_method' => $paymentMethod->id,
    'payment_method_types' => [$Methodtype],
    'confirmation_method' => 'manual', // 手动确认支付
    'confirm' => true, // 直接确认支付
    'return_url' => 'https://your-return-url.com' // 支付完成后的跳转 URL
];

if ($Methodtype = 'wechat_pay') {
	$paymentIntentParams['payment_method_options']['wechat_pay']['client']='web';
}

$paymentIntent = $stripe->paymentIntents->create($paymentIntentParams);

if (isset($paymentIntent->next_action->alipay_handle_redirect->url)) {
	print_r($paymentIntent->next_action->alipay_handle_redirect->url);
}

if (isset($paymentIntent->next_action->wechat_pay_display_qr_code->image_data_url)) {
	print_r($paymentIntent->next_action->wechat_pay_display_qr_code->image_data_url);
}

//$paymentIntent = $stripe->paymentIntents->retrieve($paymentIntent->id);
//print_r($paymentIntent);

 

支付宝 Tips

支付宝的native_url为空 可以补全为 https://intlmapi.alipay.com/gateway.do?

native_url 加上native_data 可以实现手机 app 唤醒支付

$paymentIntent->next_action->alipay_handle_redirect->native_data

微信 Tips

微信内部支付引用 data

$paymentIntent->next_action->wechat_pay_display_qr_code->data  

image_data_url为 base64 的二维码 png 图片

 

更多数据查看$paymentIntent 

 

添加新评论 »