mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Use ExperienceContext in Oxxo
This commit is contained in:
parent
41b9585d2b
commit
a2d299ef2e
3 changed files with 61 additions and 11 deletions
|
@ -1543,6 +1543,7 @@ return array(
|
|||
$container->get( 'api.endpoint.order' ),
|
||||
$container->get( 'api.factory.purchase-unit' ),
|
||||
$container->get( 'api.factory.shipping-preference' ),
|
||||
$container->get( 'wcgateway.builder.experience-context' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
|
|
|
@ -13,8 +13,11 @@ use Psr\Log\LoggerInterface;
|
|||
use WC_Order;
|
||||
use WC_Payment_Gateway;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
|
@ -79,12 +82,18 @@ class OXXOGateway extends WC_Payment_Gateway {
|
|||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* The ExperienceContextBuilder.
|
||||
*/
|
||||
protected ExperienceContextBuilder $experience_context_builder;
|
||||
|
||||
/**
|
||||
* OXXOGateway constructor.
|
||||
*
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping preference factory.
|
||||
* @param ExperienceContextBuilder $experience_context_builder The ExperienceContextBuilder.
|
||||
* @param string $module_url The URL to the module.
|
||||
* @param TransactionUrlProvider $transaction_url_provider The transaction url provider.
|
||||
* @param Environment $environment The environment.
|
||||
|
@ -94,6 +103,7 @@ class OXXOGateway extends WC_Payment_Gateway {
|
|||
OrderEndpoint $order_endpoint,
|
||||
PurchaseUnitFactory $purchase_unit_factory,
|
||||
ShippingPreferenceFactory $shipping_preference_factory,
|
||||
ExperienceContextBuilder $experience_context_builder,
|
||||
string $module_url,
|
||||
TransactionUrlProvider $transaction_url_provider,
|
||||
Environment $environment,
|
||||
|
@ -121,6 +131,7 @@ class OXXOGateway extends WC_Payment_Gateway {
|
|||
$this->order_endpoint = $order_endpoint;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->shipping_preference_factory = $shipping_preference_factory;
|
||||
$this->experience_context_builder = $experience_context_builder;
|
||||
$this->module_url = $module_url;
|
||||
$this->logger = $logger;
|
||||
|
||||
|
@ -176,17 +187,30 @@ class OXXOGateway extends WC_Payment_Gateway {
|
|||
'checkout'
|
||||
);
|
||||
|
||||
$order = $this->order_endpoint->create( array( $purchase_unit ), $shipping_preference );
|
||||
$payment_source_data = array(
|
||||
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||
'email' => $wc_order->get_billing_email(),
|
||||
'country_code' => $wc_order->get_billing_country(),
|
||||
'experience_context' => $this->experience_context_builder
|
||||
->with_default_paypal_config( $shipping_preference )
|
||||
->build()->to_array(),
|
||||
);
|
||||
|
||||
$order = $this->order_endpoint->create(
|
||||
array( $purchase_unit ),
|
||||
$shipping_preference,
|
||||
null,
|
||||
ApplicationContext::USER_ACTION_CONTINUE,
|
||||
'',
|
||||
array(),
|
||||
new PaymentSource(
|
||||
'oxxo',
|
||||
(object) $payment_source_data
|
||||
)
|
||||
);
|
||||
$this->add_paypal_meta( $wc_order, $order, $this->environment );
|
||||
|
||||
$payment_source = array(
|
||||
'oxxo' => array(
|
||||
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||
'email' => $wc_order->get_billing_email(),
|
||||
'country_code' => $wc_order->get_billing_country(),
|
||||
),
|
||||
);
|
||||
$payment_method = $this->order_endpoint->confirm_payment_source( $order->id(), $payment_source );
|
||||
$payment_method = $this->order_endpoint->confirm_payment_source( $order->id(), array( 'oxxo' => $payment_source_data ) );
|
||||
foreach ( $payment_method->links as $link ) {
|
||||
if ( $link->rel === 'payer-action' ) {
|
||||
$payer_action = $link->href;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue