mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Use ExperienceContext in renewals
This commit is contained in:
parent
a2d299ef2e
commit
ab5ddd9fab
3 changed files with 20 additions and 6 deletions
|
@ -46,7 +46,8 @@ return array(
|
|||
$container->get( 'wc-subscriptions.helpers.real-time-account-updater' ),
|
||||
$container->get( 'wc-subscriptions.helper' ),
|
||||
$container->get( 'api.endpoint.payment-tokens' ),
|
||||
$container->get( 'vaulting.wc-payment-tokens' )
|
||||
$container->get( 'vaulting.wc-payment-tokens' ),
|
||||
$container->get( 'wcgateway.builder.experience-context' )
|
||||
);
|
||||
},
|
||||
'wc-subscriptions.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository {
|
||||
|
|
|
@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||
|
@ -148,6 +149,11 @@ class RenewalHandler {
|
|||
*/
|
||||
private $wc_payment_tokens;
|
||||
|
||||
/**
|
||||
* The ExperienceContextBuilder.
|
||||
*/
|
||||
private ExperienceContextBuilder $experience_context_builder;
|
||||
|
||||
/**
|
||||
* RenewalHandler constructor.
|
||||
*
|
||||
|
@ -165,6 +171,7 @@ class RenewalHandler {
|
|||
* @param SubscriptionHelper $subscription_helper Subscription helper.
|
||||
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
|
||||
* @param WooCommercePaymentTokens $wc_payment_tokens WooCommerce payments tokens factory.
|
||||
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
|
||||
*/
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
|
@ -180,7 +187,8 @@ class RenewalHandler {
|
|||
RealTimeAccountUpdaterHelper $real_time_account_updater_helper,
|
||||
SubscriptionHelper $subscription_helper,
|
||||
PaymentTokensEndpoint $payment_tokens_endpoint,
|
||||
WooCommercePaymentTokens $wc_payment_tokens
|
||||
WooCommercePaymentTokens $wc_payment_tokens,
|
||||
ExperienceContextBuilder $experience_context_builder
|
||||
) {
|
||||
|
||||
$this->logger = $logger;
|
||||
|
@ -197,6 +205,7 @@ class RenewalHandler {
|
|||
$this->subscription_helper = $subscription_helper;
|
||||
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
|
||||
$this->wc_payment_tokens = $wc_payment_tokens;
|
||||
$this->experience_context_builder = $experience_context_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,12 +551,15 @@ class RenewalHandler {
|
|||
*/
|
||||
private function card_payment_source( string $token, WC_Order $wc_order ): PaymentSource {
|
||||
$properties = array(
|
||||
'vault_id' => $token,
|
||||
'stored_credential' => array(
|
||||
'vault_id' => $token,
|
||||
'stored_credential' => array(
|
||||
'payment_initiator' => 'MERCHANT',
|
||||
'payment_type' => 'RECURRING',
|
||||
'usage' => 'SUBSEQUENT',
|
||||
),
|
||||
'experience_context' => $this->experience_context_builder
|
||||
->with_endpoint_return_urls()
|
||||
->build()->to_array(),
|
||||
);
|
||||
|
||||
$subscriptions = wcs_get_subscriptions_for_renewal_order( $wc_order );
|
||||
|
|
|
@ -13,7 +13,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSourceCard;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
|
@ -82,6 +81,8 @@ class VaultedCreditCardHandlerTest extends TestCase
|
|||
$token = Mockery::mock(PaymentToken::class);
|
||||
$tokenId = 'abc123';
|
||||
$token->shouldReceive('id')->andReturn($tokenId);
|
||||
$requestPaymentSource = Mockery::mock(PaymentSource::class);
|
||||
$token->shouldReceive('to_payment_source')->andReturn($requestPaymentSource);
|
||||
$this->paymentTokenRepository->shouldReceive('all_for_user_id')
|
||||
->andReturn([$token]);
|
||||
|
||||
|
@ -124,7 +125,7 @@ class VaultedCreditCardHandlerTest extends TestCase
|
|||
$purchaseUnit->shouldReceive('payments')->andReturn($payments);
|
||||
|
||||
$this->orderEndpoint->shouldReceive('create')
|
||||
->with([$purchaseUnit], 'some_preference', $payer, $token)
|
||||
->with([$purchaseUnit], 'some_preference', $payer, 'CONTINUE', '', array(), $requestPaymentSource)
|
||||
->andReturn($order);
|
||||
|
||||
$this->environment->shouldReceive('current_environment_is')->andReturn(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue