PHP致命错误:未捕获(状态400)eu_vat Stripe支付网关的值无效



我根据条带库进行编码,但我有一个404:

【11月25日星期三09:35:26。2020][php7:error][pid 7014][client]PHP致命错误:未捕获(状态400((请求req_…..(eu_vat的值无效。\N在/homehttp://data/https://.fr/wp-content/themes/sq/stripe-php-master/lib/Exception/ApiErrorException.php第38行抛出,referr:https://***.fr/checkout/

// STRIPE STRIPE STRIPE
<?php
require_once('./stripe-php-master/init.php');
$stripe = new StripeStripeClient("sk_test_--------");
$curl = new StripeHttpClientCurlClient([CURLOPT_PROXY => '*****:3128']);
StripeApiRequestor::setHttpClient($curl);
$address_line_1 = $_COOKIE["billing_address_1"];
$phone = $_COOKIE["billing_phone"];
$first_name = $_COOKIE["billing_first_name"];
$last_name = $_COOKIE["billing_last_name"];
$siret = $_COOKIE["billing_siret"];
$TaxId = $_COOKIE["billing_TaxId"] ? $_COOKIE["billing_TaxId"] : ($_POST['TaxId'] ? $_POST['TaxId'] : NULL);
$email = $_COOKIE["billing_email"];

$cart = !empty($_COOKIE['cart']) ? $_COOKIE['cart'] : NULL;
$billing_country = !empty($_COOKIE['billing_country']) ? $_COOKIE['billing_country'] : NULL;
// $country = $_COOKIE["billing_country"];
$company_name = $_COOKIE["billing_company"];
// If Allemagne - Belgique - Autriche - Bosnie herzegovie - Russie - Suisse -> state mandatory
$state = $_COOKIE["billing_state"];
$post_code = $_COOKIE["billing_postcode"];
$city = $_COOKIE["billing_city"];
$stripe_token = !empty($_COOKIE['stripe_token']) ? $_COOKIE['stripe_token'] : NULL;
// $stripe_token = $_COOKIE["stripe_tkn"];
$arrival_date = !empty($_COOKIE['arrival_date']) ? $_COOKIE['arrival_date'] : NULL;
// $arrival_date = $_COOKIE["arrival_date"];
$engagement_period = !empty($_COOKIE['engagement_period']) ? $_COOKIE['engagement_period'] : NULL;
// $engagement_period = $_COOKIE["engagement_period"];
$monthly_frequency = !empty($_COOKIE['monthly_frequency']) ? $_COOKIE['monthly_frequency'] : NULL;
// $monthly_frequency = $_COOKIE["monthly_frequency"];
$quantity_office = !empty($_COOKIE['quantity_office']) ? $_COOKIE['quantity_office'] : NULL;
// $quantity_office = $_COOKIE["quantity_office"];
$parking_spot = !empty($_COOKIE['parking_spot']) ? $_COOKIE['parking_spot'] : NULL;
// $parking_spot = $_COOKIE["parking_spot"];
$price_str = $_COOKIE["price"];
$created_customer = $stripe->customers->create([
'address' => [
'line1' => $address_line_1,
'country' => $country,
'state' => $state,
'city' => $city,
],
'email' => $email,
'phone' => $phone,
'metadata' => [
'Periode_engagement' => $engagement_period,
'Frequence_mensuelle' => $monthly_frequency,
'Nombre_poste' => $quantity_office,
'Place_parking' => $parking_spot,
],
'name' => $company_name,
'description' => $company_name,
'invoice_settings' => [
'custom_fields' => [
[
'name' => 'SIRET',
'value' => 'FRAB123456789',
],
],
],
]);
$customer_id = $created_customer->id;
$tax_id = $stripe->customers->createTaxId(
$created_customer->id,
[
'type' => 'eu_vat',
'value' => $TaxId,
]
);
$customer_card = $stripe->customers->createSource(
$customer_id,
['source' => $stripe_token]
);
$engagement_number = (int) filter_var($engagement_period, FILTER_SANITIZE_NUMBER_INT);
$final_price = floatval(str_replace(',', '.', str_replace('.', '', $price_str))) / $engagement_number;
$price = $stripe->prices->create([
'currency' => 'eur',
'unit_amount' => $final_price,
'recurring' => [
'interval' => 'month'
],
'product_data' => [
'name' => 'NS Subscription'
]
]);
$engagement_period_string = "first day of +".$engagement_number." month";
$date = new DateTime('now');
$nowTimestamp = $date->getTimestamp();
$date->modify('first day of next month');
$firstDayOfNextMonthTimestamp = $date->getTimestamp();
// check month subscriptions for cancel date
$date_end = new DateTime('now');
$date_end->modify($engagement_period_string);
$cancel_date_timestamp = $date_end->getTimestamp();
$sub = $stripe->subscriptions->create([
'customer' => $customer_id,
'items' => [
[
'price' => $price->id
],
],
'billing_cycle_anchor' => $firstDayOfNextMonthTimestamp,
'cancel_at' => $cancel_date_timestamp
]);
?>

它在本地工作,但一旦上线,在同一个PHP版本下,我们就会遇到一个错误。我承认我不明白。如果有人有解决方案空缺?

谢谢大家,

错误是由于使用给定的stripe API版本升级https://stripe.com/docs/upgrades#2019-12-03,税务ID的行为已经改变

请检查您的本地和测试版API版本。如果版本相同,请将createTaxId调用包含在InvalidRequestException try-catch块中

最新更新