Я создаю платежный шлюз на базе Stripe для платформы электронной коммерции. Когда я go к оформлению заказа, я получаю сообщение об ошибке «У клиента должен быть подключен активный источник оплаты». Однако, когда я регистрирую результаты из \ Stripe \ PaymentMethod :: все методы оплаты для клиента возвращаются.
Вот фрагмент кода из проблемной области.
\Stripe\Stripe::setApiKey($this->secret_key);
$intentID = $_POST['intentID'];
$setup_intent = \Stripe\SetupIntent::retrieve($intentID);
//save payment method id to customer
$customer = \Stripe\Customer::create(['payment_method' => $setup_intent->payment_method]);
//get all customer payment methods
$payment_methods = \Stripe\PaymentMethod::all([
'customer' => $customer->id,
'type' => 'card',
]);
//if vendor is connected to stripe create token
if ( ! empty( $access_token ) ) {
try{
$token = \Stripe\Token::create( array( 'customer' => $customer->id ), $access_token );
}catch(Exception $e){
var_error_log($e->getMessage());
}
} else if ( $this->allow_unconnected_sellers == 'yes' ) {
$token = null;
} else {
wc_add_notice('Unable to process with Stripe gateway', 'error');
return;
}
Цель платежа получена и имеет идентификатор метода оплаты. Это то, что переменная $ setup_intent возвращает, когда я регистрирую ее.
[25-Feb-2020 16:21:37 UTC] object(Stripe\SetupIntent)#2877 (20) {
["id"]=>
string(29) "seti_1GG69pL8ByYsKvROh2NNVQya"
["object"]=>
string(12) "setup_intent"
["application"]=>
NULL
["cancellation_reason"]=>
NULL
["client_secret"]=>
string(68) "seti_1GG69pL8ByYsKvROh2NNVQya_secret_GnhYhOiZIVQJMapNMR9ZpfOzhEXzt1B"
["created"]=>
int(1582647677)
["customer"]=>
NULL
["description"]=>
NULL
["last_setup_error"]=>
NULL
["livemode"]=>
bool(false)
["mandate"]=>
NULL
["metadata"]=>
object(Stripe\StripeObject)#2948 (0) {
}
["next_action"]=>
NULL
["on_behalf_of"]=>
NULL
["payment_method"]=>
string(27) "pm_1GG6A5L8ByYsKvROlbLS4YOi"
["payment_method_options"]=>
object(Stripe\StripeObject)#2909 (1) {
["card"]=>
object(Stripe\StripeObject)#2960 (1) {
["request_three_d_secure"]=>
string(9) "automatic"
}
}
["payment_method_types"]=>
array(1) {
[0]=>
string(4) "card"
}
["single_use_mandate"]=>
NULL
["status"]=>
string(9) "succeeded"
["usage"]=>
string(11) "off_session"
}
Вот что возвращается, когда я записываю переменную $ customer.
[25-Feb-2020 16:21:37 UTC] object(Stripe\Customer)#2947 (26) {
["id"]=>
string(18) "cus_GnhZUhQOCslFcl"
["object"]=>
string(8) "customer"
["account_balance"]=>
int(0)
["address"]=>
NULL
["balance"]=>
int(0)
["created"]=>
int(1582647696)
["currency"]=>
NULL
["default_source"]=>
NULL
["delinquent"]=>
bool(false)
["description"]=>
NULL
["discount"]=>
NULL
["email"]=>
NULL
["invoice_prefix"]=>
string(8) "10DD54AF"
["invoice_settings"]=>
object(Stripe\StripeObject)#2838 (3) {
["custom_fields"]=>
NULL
["default_payment_method"]=>
NULL
["footer"]=>
NULL
}
["livemode"]=>
bool(false)
["metadata"]=>
object(Stripe\StripeObject)#2837 (0) {
}
["name"]=>
NULL
["phone"]=>
NULL
["preferred_locales"]=>
array(0) {
}
["shipping"]=>
NULL
["sources"]=>
object(Stripe\Collection)#2995 (5) {
["object"]=>
string(4) "list"
["data"]=>
array(0) {
}
["has_more"]=>
bool(false)
["total_count"]=>
int(0)
["url"]=>
string(40) "/v1/customers/cus_GnhZUhQOCslFcl/sources"
}
["subscriptions"]=>
object(Stripe\Collection)#2992 (5) {
["object"]=>
string(4) "list"
["data"]=>
array(0) {
}
["has_more"]=>
bool(false)
["total_count"]=>
int(0)
["url"]=>
string(46) "/v1/customers/cus_GnhZUhQOCslFcl/subscriptions"
}
["tax_exempt"]=>
string(4) "none"
["tax_ids"]=>
object(Stripe\Collection)#2989 (5) {
["object"]=>
string(4) "list"
["data"]=>
array(0) {
}
["has_more"]=>
bool(false)
["total_count"]=>
int(0)
["url"]=>
string(40) "/v1/customers/cus_GnhZUhQOCslFcl/tax_ids"
}
["tax_info"]=>
NULL
["tax_info_verification"]=>
NULL
}
Я также зарегистрировал результат переменная $ payment_methods. Методы оплаты для клиента возвращаются вместе с идентификатором метода оплаты.
[25-Feb-2020 16:21:37 UTC] object(Stripe\Collection)#2986 (4) {
["object"]=>
string(4) "list"
["data"]=>
array(1) {
[0]=>
object(Stripe\PaymentMethod)#2978 (9) {
["id"]=>
string(27) "pm_1GG6A5L8ByYsKvROlbLS4YOi"
["object"]=>
string(14) "payment_method"
["billing_details"]=>
object(Stripe\StripeObject)#2974 (4) {
["address"]=>
object(Stripe\StripeObject)#2972 (6) {
["city"]=>
NULL
["country"]=>
NULL
["line1"]=>
NULL
["line2"]=>
NULL
["postal_code"]=>
string(5) "19104"
["state"]=>
NULL
}
["email"]=>
NULL
["name"]=>
string(8) "John Doe"
["phone"]=>
NULL
}
["card"]=>
object(Stripe\StripeObject)#2973 (11) {
["brand"]=>
string(4) "visa"
["checks"]=>
object(Stripe\StripeObject)#2793 (3) {
["address_line1_check"]=>
NULL
["address_postal_code_check"]=>
string(4) "pass"
["cvc_check"]=>
string(4) "pass"
}
["country"]=>
string(2) "US"
["exp_month"]=>
int(4)
["exp_year"]=>
int(2024)
["fingerprint"]=>
string(16) "MIexcoDyPrQncpp1"
["funding"]=>
string(6) "credit"
["generated_from"]=>
NULL
["last4"]=>
string(4) "4242"
["three_d_secure_usage"]=>
object(Stripe\StripeObject)#2971 (1) {
["supported"]=>
bool(true)
}
["wallet"]=>
NULL
}
["created"]=>
int(1582647693)
["customer"]=>
string(18) "cus_GnhZUhQOCslFcl"
["livemode"]=>
bool(false)
["metadata"]=>
object(Stripe\StripeObject)#2969 (0) {
}
["type"]=>
string(4) "card"
}
}
["has_more"]=>
bool(false)
["url"]=>
string(19) "/v1/payment_methods"
}