mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-02-08 18:08:13 -05:00
[update] 新增credit card跳转至checkout页面付款
This commit is contained in:
parent
f0c620cbc2
commit
acb40cc1f9
@ -37,7 +37,7 @@ class StripeALLInOne {
|
|||||||
],
|
],
|
||||||
'payment_method' => [
|
'payment_method' => [
|
||||||
'label' => '支付方式',
|
'label' => '支付方式',
|
||||||
'description' => '请输入alipay或者wechat_pay',
|
'description' => '请输入alipay, wechat_pay, cards',
|
||||||
'type' => 'input',
|
'type' => 'input',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
@ -50,9 +50,12 @@ class StripeALLInOne {
|
|||||||
if (!$exchange) {
|
if (!$exchange) {
|
||||||
throw new ApiException('Currency conversion has timed out, please try again later', 500);
|
throw new ApiException('Currency conversion has timed out, please try again later', 500);
|
||||||
}
|
}
|
||||||
|
//jump url
|
||||||
|
$jumpUrl = null;
|
||||||
|
$actionType = 0;
|
||||||
$stripe = new \Stripe\StripeClient($this->config['stripe_sk_live']);
|
$stripe = new \Stripe\StripeClient($this->config['stripe_sk_live']);
|
||||||
|
|
||||||
|
if ($this->config['payment_method'] != "cards"){
|
||||||
$stripePaymentMethod = $stripe->paymentMethods->create([
|
$stripePaymentMethod = $stripe->paymentMethods->create([
|
||||||
'type' => $this->config['payment_method'],
|
'type' => $this->config['payment_method'],
|
||||||
]);
|
]);
|
||||||
@ -85,9 +88,7 @@ class StripeALLInOne {
|
|||||||
$stripeIntents = $stripe->paymentIntents->create($params);
|
$stripeIntents = $stripe->paymentIntents->create($params);
|
||||||
|
|
||||||
$nextAction = null;
|
$nextAction = null;
|
||||||
//jump url
|
|
||||||
$jumpUrl = null;
|
|
||||||
$actionType = 0;
|
|
||||||
if (!$stripeIntents['next_action']) {
|
if (!$stripeIntents['next_action']) {
|
||||||
throw new ApiException(__('Payment gateway request failed'));
|
throw new ApiException(__('Payment gateway request failed'));
|
||||||
}else {
|
}else {
|
||||||
@ -110,6 +111,30 @@ class StripeALLInOne {
|
|||||||
throw new ApiException('unable get WeChat Pay redirect url', 500);
|
throw new ApiException('unable get WeChat Pay redirect url', 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$creditCheckOut = $stripe->checkout->sessions->create([
|
||||||
|
'success_url' => $order['return_url'],
|
||||||
|
'client_reference_id' => $order['trade_no'],
|
||||||
|
'payment_method_types' => ['card'],
|
||||||
|
'line_items' => [
|
||||||
|
[
|
||||||
|
'price_data' => [
|
||||||
|
'currency' => $currency,
|
||||||
|
'unit_amount' => floor($order['total_amount'] * $exchange),
|
||||||
|
'product_data' => [
|
||||||
|
'name' => 'sub-' . $order['user_id'] . '-' . substr($order['trade_no'], -8),
|
||||||
|
'description' => $this->config['description'],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'quantity' => 1,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'mode' => 'payment',
|
||||||
|
]);
|
||||||
|
$jumpUrl = $creditCheckOut['url'];
|
||||||
|
$actionType = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'type' => $actionType,
|
'type' => $actionType,
|
||||||
'data' => $jumpUrl
|
'data' => $jumpUrl
|
||||||
@ -133,7 +158,6 @@ class StripeALLInOne {
|
|||||||
|
|
||||||
} catch (\UnexpectedValueException $e){
|
} catch (\UnexpectedValueException $e){
|
||||||
throw new ApiException('Error parsing payload', 400);
|
throw new ApiException('Error parsing payload', 400);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (\Stripe\Exception\SignatureVerificationException $e) {
|
catch (\Stripe\Exception\SignatureVerificationException $e) {
|
||||||
throw new ApiException('signature not match', 400);
|
throw new ApiException('signature not match', 400);
|
||||||
@ -153,6 +177,22 @@ class StripeALLInOne {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'checkout.session.completed':
|
||||||
|
$object = $event->data->object;
|
||||||
|
if ($object->payment_status === 'paid') {
|
||||||
|
return [
|
||||||
|
'trade_no' => $object->client_reference_id,
|
||||||
|
'callback_no' => $object->payment_intent
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'checkout.session.async_payment_succeeded':
|
||||||
|
$object = $event->data->object;
|
||||||
|
return [
|
||||||
|
'trade_no' => $object->client_reference_id,
|
||||||
|
'callback_no' => $object->payment_intent
|
||||||
|
];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ApiException('event is not support');
|
throw new ApiException('event is not support');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user