PHP Stripe API 从令牌添加支付源时出错
PHP Stripe API error on add payment source from token
我收到以下错误:-
我想我没有得到 $payment_source_id,而是无法生成 $payment_source_id,
由此
$payment_source_id = $this->add_payment_source_from_token( $customer_id, $token_id,
$invoice );
它对应的函数是:-
private function add_payment_source_from_token( $customer_id, $token_id, SI_Invoice
$invoice ) {
$customer = self::get_customer_object( $customer_id );
if ( ! $customer ) {
do_action( 'si_error', __CLASS__ . '::' . __FUNCTION__ . ' response: ', $customer );
return;
}
self::setup_stripe();
try {
$card = $customer->sources->create( array( 'source' => $token_id ) );
} catch (Exception $e) {
self::set_error_messages( $e->getMessage() );
return false;
}
$source_id = $card->id;
if ( ! isset( $_POST['sa_credit_store_payment_profile'] ) && ! isset( $checkout-
>cache['sa_credit_store_payment_profile'] ) )
{Sprout_Billings_Profiles::hide_payment_profile( $source_id, $invoice->get_id() );}
return $source_id;
}
任何人都可以指出哪里出了问题以及应该是什么,我认为这将解决这里的问题,这将是一个很大的帮助。尽早回复将不胜感激,提前致谢。对了我的stripe库是stripe-php-6.31.0.
根据错误 Call to a member function create() on null
,我假设错误源于此行:
$card = $customer->sources->create( array( 'source' => $token_id ) );
这可能是因为客户 sources
are expandable, meaning they are not returned by default. You must explicitly request expanded properties during retrieval. For Customer sources in stripe-php
prior to the changes in 7.33.0 这将是:
\Stripe\Customer::retrieve(
'cus_123',
[ 'expand' => ['sources']]
);
对于 7.33.0+,它将是:
$stripe->customers->retrieve(
'cus_123',
['expand' => ['sources']]
);
我不确定您如何通过 get_customer_object
传递 expand
参数,但您需要单独调查。
我收到以下错误
我想我没有得到 $payment_source_id,而是无法生成 $payment_source_id,
由此
$payment_source_id = $this->add_payment_source_from_token( $customer_id, $token_id,
$invoice );
它对应的函数是:-
private function add_payment_source_from_token( $customer_id, $token_id, SI_Invoice
$invoice ) {
$customer = self::get_customer_object( $customer_id );
if ( ! $customer ) {
do_action( 'si_error', __CLASS__ . '::' . __FUNCTION__ . ' response: ', $customer );
return;
}
self::setup_stripe();
try {
$card = $customer->sources->create( array( 'source' => $token_id ) );
} catch (Exception $e) {
self::set_error_messages( $e->getMessage() );
return false;
}
$source_id = $card->id;
if ( ! isset( $_POST['sa_credit_store_payment_profile'] ) && ! isset( $checkout-
>cache['sa_credit_store_payment_profile'] ) )
{Sprout_Billings_Profiles::hide_payment_profile( $source_id, $invoice->get_id() );}
return $source_id;
}
任何人都可以指出哪里出了问题以及应该是什么,我认为这将解决这里的问题,这将是一个很大的帮助。尽早回复将不胜感激,提前致谢。对了我的stripe库是stripe-php-6.31.0.
根据错误 Call to a member function create() on null
,我假设错误源于此行:
$card = $customer->sources->create( array( 'source' => $token_id ) );
这可能是因为客户 sources
are expandable, meaning they are not returned by default. You must explicitly request expanded properties during retrieval. For Customer sources in stripe-php
prior to the changes in 7.33.0 这将是:
\Stripe\Customer::retrieve(
'cus_123',
[ 'expand' => ['sources']]
);
对于 7.33.0+,它将是:
$stripe->customers->retrieve(
'cus_123',
['expand' => ['sources']]
);
我不确定您如何通过 get_customer_object
传递 expand
参数,但您需要单独调查。