Add create payment token for credit card (work in progress)

This commit is contained in:
dinamiko 2021-05-17 11:00:57 +02:00
parent da4388c507
commit 1783467af4
5 changed files with 157 additions and 3 deletions

View file

@ -101,6 +101,22 @@ class PaymentTokenRepository {
return $this->endpoint->delete_token( $token );
}
/**
* Create payment token for customer.
*
* @param int $customer_id The customer Id.
* @param array $source The payment source.
* @return PaymentToken
* @throws RuntimeException If the request fails.
*/
public function create( $customer_id, $source ): PaymentToken {
try {
return $this->endpoint->create( $customer_id, $source );
} catch ( RuntimeException $exception ) {
throw new RuntimeException( $exception->getMessage() );
}
}
/**
* Fetch PaymentToken from PayPal for a user.
*

View file

@ -111,7 +111,7 @@ class SubscriptionModule implements ModuleInterface {
$tokens = $payment_token_repository->all_for_user_id( $subscription->get_customer_id() );
if ( $tokens ) {
$subscription_id = $subscription->get_id();
$latest_token_id = end( $tokens )->id() ?: '';
$latest_token_id = end( $tokens )->id() ? end( $tokens )->id() : '';
update_post_meta( $subscription_id, 'payment_token_id', $latest_token_id, true );
}
} catch ( RuntimeException $error ) {