我在让我的条纹结帐会话工作有很多麻烦.以前在使付款直接收费到连接的帐户,并采取费用,一切都工作正常.现在与更新的代码,一切功能如预期的期望时返回的URL.这提供了一个500错误,由于结帐会话未被识别,我假设。创建结帐会话的当前代码如下。
try {
// Calculate the amount in Stripe's smallest unit
$stripeAmount = $this->calculateStripeAmount($request['amounts'][$configItem['currency']]);
// Calculate the 10% fee
$feeAmount = $this->calculateFeeAmount($request['amounts'][$configItem['currency']]);
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => $paymentMethodTypes,
'customer_email' => $request['payer_email'],
'client_reference_id' => $request['order_id'],
'line_items' => [[
'price_data' => [
'currency' => $configItem['currency'],
'unit_amount' => $this->calculateStripeAmount($request['amounts'][$configItem['currency']]),
'product_data' => [
'name' => $request['item_name'],
'description' => $request['description'],
]
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => getAppUrl($configItem['callbackUrl']) . '?stripe_session_id={CHECKOUT_SESSION_ID}' . '&paymentOption=stripe&orderId=' . $request['order_id'],
'cancel_url' => getAppUrl($configItem['callbackUrl']) . '?stripe_session_id={CHECKOUT_SESSION_ID}' . '&paymentOption=stripe&orderId=' . $request['order_id'],
'payment_intent_data' => [
'application_fee_amount' => $feeAmount,
],
], ['stripe_account' => $request['stripe_connect_account_id']],
);
return $session;
} catch (Exception $e) {
//if payment failed set failed message
$errorMessage = [
'message' => 'failed',
'errorMessage' => $e->getMessage(),
'trace' => $e->getTraceAsString() // This will help in debugging
];
return (array) $errorMessage;
}
}
/**
* Retrieve Stripe data by session Id
*
* @param string $sessionId
*
* request to Stripe checkout
*---------------------------------------------------------------- */
public function retrieveStripeData($sessionId)
{
try {
$sessionData = \Stripe\Checkout\Session::retrieve($sessionId);
if (empty($sessionData)) {
throw new Exception("Session data does not exist.");
}
$paymentIntentData = \Stripe\PaymentIntent::retrieve($sessionData->payment_intent);
return $paymentIntentData;
} catch (\Stripe\Error\InvalidRequest $err) {
//set error message if payment failed
$errorMessage['errorMessage'] = $err->getMessage();
//return error message array
return (array) $errorMessage;
} catch (\Stripe\Error\Card $err) {
//set error message if payment failed
$errorMessage['errorMessage'] = $err->getMessage();
//return error message array
return (array) $errorMessage;
}
}
字符串
这里是另一个文件中的前端,忽略不使用变量的公钥,因为这是故意的,需要删除。
if(payWidth == 'stripe'){
$(".payment_method_box").css("pointer-events", "auto");
$(".loaderWrapper").remove();
//config data For Stripe
var configData = <?php echo json_encode($PublicConfigs); ?> ,
configItem = configData['payments']['gateway_configuration']['stripe'],
userDetails = <?php echo json_encode($DataUserDetails); ?> ,
stripePublishKey = '';
//check stripe test or production mode
if (configItem['testMode'] === 'true') {
stripePublishKey = '<?php echo $stripePaymentTestPublicKey;?>';
} else {
stripePublishKey = '<?php echo $stripePaymentLivePublicKey;?>';
}
/*if (configItem['testMode']) {
stripePublishKey = configItem['stripeTestingPublishKey'];
} else {
stripePublishKey = configItem['stripeLivePublishKey'];
}*/
userDetails['paymentOption'] = payWidth;
userDetails['f'] = 'processProduct';
userDetails['creditPlan'] = planID;
// Stripe script for send ajax request to server side start
$.ajax({
type: 'post', //form method
context: this,
url: siteurl + 'requests/request.php', // post data url
dataType: "JSON",
data: userDetails, // form serialize data
error: function(err) {
var error = err.responseText
string = '';
alert(err.responseText);
},
success: function(response) {
//alert(response.id);
var stripe = Stripe('pk_test_51NfvLOJKlCTqPFwWMLFchWWnSWqy8v1JECWnjMSUxaUfomcl1ru5gSpxh3u395GPwDy23oVMK7tFpfAYuhkOkZwl009owSqTbq', {
stripeAccount: ('<?php echo $stripeConnectAccountId;?>')
});
//alert(stripe);
stripe.redirectToCheckout({
sessionId: response.id,
}).then(function(result) {
var string = '';
alert(result.error.message);
});
}
});
}
型
以及下面的条带日志提供的错误。
我对js和php很陌生,这可能会在代码中表现出来。我知道这是一个很大的问题,但如果有人能提供指导,说明问题可能来自哪里,我将不胜感激。
我的一个想法是,客户可能是在平台下创建的,而结帐会话是在连接的帐户下。我试图创建一个客户,并使用相同的行与stripe_account,但结果是相同的。
1条答案
按热度按时间juud5qan1#
此错误通常意味着结帐会话是在帐户A中创建的,但您正在从帐户B中检索它。
由于Checkout Session是在Direct Charges下创建的,即Checkout Session是在连接账户(非平台账户)中创建的,因此检索请求中还应包含
Stripe-Account
头作为请求中的连接账户ID。如果没有Stripe-Account
头,则会在平台账户中查找Checkout Session。比如说,
字符串