gpt4 book ai didi

php - Stripe 3d 安全订阅失败

转载 作者:行者123 更新时间:2023-12-02 08:13:57 26 4
gpt4 key购买 nike

我对 Stripe 的测试环境有一个关于 3D 安全流程和订阅的问题。我担心在没有验证或解释问题的情况下将流程推向生产。

我根据文档执行了所有 3d 安全和订阅流程。

https://stripe.com/docs/sources/three-d-secure/subscriptions

当我通过禁用试用期来激活订阅时,我所做的所有尝试都失败了。

enter image description here

我正在使用需要 3d secure 的测试卡:4000 0000 0000 3063

我的代码流程:

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Source test Stripe</title>
<script src="https://js.stripe.com/v3/"></script>
<style>
.StripeElement {
background-color: white;
height: 40px;
padding: 10px 12px;
border-radius: 4px;
border: 1px solid transparent;
box-shadow: 0 1px 3px 0 #e6ebf1;
-webkit-transition: box-shadow 150ms ease;
transition: box-shadow 150ms ease;
}

.StripeElement--focus {
box-shadow: 0 1px 3px 0 #cfd7df;
}

.StripeElement--invalid {
border-color: #fa755a;
}

.StripeElement--webkit-autofill {
background-color: #fefde5 !important;
}
</style>

</head>
<body>
<h1>create source</h1>

<form action="javascript:charge()" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
</div>
<div id="card-errors" role="alert"></div>
</div>
<button>Submit Payment</button>
</form>

</body>
<script>
var stripe = Stripe('pk_test_xxxx');
var elements = stripe.elements();
var style = {
base: {
color: '#32325d',
lineHeight: '18px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
var card = elements.create('card', {style: style});
card.mount('#card-element');

card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});

var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();

var ownerInfo = {
owner: {
name: 'Jenny Rosen',
address: {
line1: 'Nollendorfstraße 27',
city: 'Berlin',
postal_code: '10777',
country: 'DE',
},
email: 'jenny.rosen@example.com'
},
};
stripe.createSource(card, ownerInfo).then(function(result) {
if (result.error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
console.log(result.source.id)
}
});
});

function charge() {
}
</script>
</html>

我得到了源 ID src_xxxxx

我放入了我的 php 脚本:

<?php

require_once('stripe-php/init.php');

Stripe\Stripe::setApiKey(
'sk_test_xxxxx'
);

$sourceId = 'src_xxxxx';

$customer = Stripe\Customer::create([
'description' => 'test desc',
'email' => 'test@test.com',
'source' => $sourceId,
]);


$param = [
"amount" => 2995,
"currency" => 'eur',
"type" => "three_d_secure",
'three_d_secure' => [
'card' => $sourceId
],
"redirect" => [
"return_url" => "http://localhost:8080/stripeProcess2.php?customerId=".$customer->id
],
];

$source = Stripe\Source::create($param);

$customer->sources->create(['source' => $source->id]);

var_dump($source->redirect);

在var_dump中,我得到了重定向url

我接受 3d 安全支付,重定向链接执行以下脚本:

<?php
require_once('stripe-php/init.php');

Stripe\Stripe::setApiKey(
'sk_test_xxxx'
);

$source = $_GET['source'];
$customerId = $_GET['customerId'];

$charges = \Stripe\Charge::create(array(
"amount" => 2995,
"currency" => "eur",
'source' => $source,
'customer' => $customerId,
"description" => "Charge for daniel.garcia@example.com"
));


$params = [
'items' => [
[
"plan" => "annual-basic",
]
],
'customer' => $customerId,
'trial_end' => strtotime('+1 day')
];


$sub = \Stripe\Subscription::create($params);

var_dump($sub->id);

通过订阅 Stripe id,我会立即激活订阅(这会向客户收费)

$subscription = \Stripe\Subscription::retrieve("sub_C7eVRi9WLynMdh");
$subscription->trial_end = "now";
$subscription->save();

在这里,我通过 generic_decline 代码收到了失败的付款。

我想知道在我的过程中是否执行了错误,是否需要等待月底为客户充值,或者 Stripe 测试卡是否无法用于此过程?

提前致谢

最佳答案

我认为拒绝的原因是因为测试卡 4000000000003063 ( https://stripe.com/docs/sources/three-d-secure ) 仅适用于单次付款,并且必须完成 3D Secure 才能成功充值。 (请使用信用卡 4000000000003055 - “此卡支持 3D Secure,但不需要”。)

这意味着,如果客户附有此卡,您只能测试初始付款,而不能测试定期付款,因为您无法再次完成 3D 安全程序。

您需要使用 strip 默认程序 ( https://stripe.com/docs/sources/cards ) 存储原始信用卡来源,以便再次使用此来源进行持续的订阅付款。

关于php - Stripe 3d 安全订阅失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48227967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com