mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Fix merge issues
This commit is contained in:
parent
5f90aaae20
commit
cbe10b5f6e
4 changed files with 77 additions and 14 deletions
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
|
||||||
|
@ -28,6 +29,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OrderEndpoint
|
* Class OrderEndpoint
|
||||||
|
@ -564,4 +566,49 @@ class OrderEndpoint {
|
||||||
$new_order = $this->order( $order_to_update->id() );
|
$new_order = $this->order( $order_to_update->id() );
|
||||||
return $new_order;
|
return $new_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirms payment source.
|
||||||
|
*
|
||||||
|
* @param string $id The PayPal order ID.
|
||||||
|
* @param array $payment_source The payment source.
|
||||||
|
* @return stdClass
|
||||||
|
* @throws PayPalApiException If the request fails.
|
||||||
|
* @throws RuntimeException If something unexpected happens.
|
||||||
|
*/
|
||||||
|
public function confirm_payment_source( string $id, array $payment_source ): stdClass {
|
||||||
|
$bearer = $this->bearer->bearer();
|
||||||
|
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id . '/confirm-payment-source';
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'payment_source' => $payment_source,
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => 'es-MX',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'method' => 'POST',
|
||||||
|
'headers' => array(
|
||||||
|
'Authorization' => 'Bearer ' . $bearer->token(),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Prefer' => 'return=representation',
|
||||||
|
),
|
||||||
|
'body' => wp_json_encode( $data ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->request( $url, $args );
|
||||||
|
if ( $response instanceof WP_Error ) {
|
||||||
|
throw new RuntimeException( $response->get_error_message() );
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = json_decode( $response['body'] );
|
||||||
|
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||||
|
if ( 200 !== $status_code ) {
|
||||||
|
throw new PayPalApiException( $json, $status_code );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2238,6 +2238,7 @@ return array(
|
||||||
return new OXXOGateway(
|
return new OXXOGateway(
|
||||||
$container->get( 'api.endpoint.order' ),
|
$container->get( 'api.endpoint.order' ),
|
||||||
$container->get( 'api.factory.purchase-unit' ),
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'api.factory.shipping-preference' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PayUponInvoiceGateway.
|
* Class PayUponInvoiceGateway.
|
||||||
|
@ -36,6 +37,13 @@ class OXXOGateway extends WC_Payment_Gateway {
|
||||||
*/
|
*/
|
||||||
protected $purchase_unit_factory;
|
protected $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The shipping preference factory.
|
||||||
|
*
|
||||||
|
* @var ShippingPreferenceFactory
|
||||||
|
*/
|
||||||
|
protected $shipping_preference_factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
*
|
*
|
||||||
|
@ -46,13 +54,15 @@ class OXXOGateway extends WC_Payment_Gateway {
|
||||||
/**
|
/**
|
||||||
* OXXOGateway constructor.
|
* OXXOGateway constructor.
|
||||||
*
|
*
|
||||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping preference factory.
|
||||||
|
* @param LoggerInterface $logger The logger.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
OrderEndpoint $order_endpoint,
|
OrderEndpoint $order_endpoint,
|
||||||
PurchaseUnitFactory $purchase_unit_factory,
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
ShippingPreferenceFactory $shipping_preference_factory,
|
||||||
LoggerInterface $logger
|
LoggerInterface $logger
|
||||||
) {
|
) {
|
||||||
$this->id = self::ID;
|
$this->id = self::ID;
|
||||||
|
@ -75,9 +85,10 @@ class OXXOGateway extends WC_Payment_Gateway {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->order_endpoint = $order_endpoint;
|
$this->order_endpoint = $order_endpoint;
|
||||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
$this->logger = $logger;
|
$this->shipping_preference_factory = $shipping_preference_factory;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,7 +133,12 @@ class OXXOGateway extends WC_Payment_Gateway {
|
||||||
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$order = $this->order_endpoint->create( array( $purchase_unit ) );
|
$shipping_preference = $this->shipping_preference_factory->from_state(
|
||||||
|
$purchase_unit,
|
||||||
|
'checkout'
|
||||||
|
);
|
||||||
|
|
||||||
|
$order = $this->order_endpoint->create( array( $purchase_unit ), $shipping_preference );
|
||||||
$payment_source = array(
|
$payment_source = array(
|
||||||
'oxxo' => array(
|
'oxxo' => array(
|
||||||
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
|
|
@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
|
||||||
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
|
||||||
|
@ -116,11 +117,9 @@ class PayUponInvoice {
|
||||||
protected $pui_product_status;
|
protected $pui_product_status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The capture factory.
|
* @var CheckoutHelper
|
||||||
*
|
|
||||||
* @var CaptureFactory
|
|
||||||
*/
|
*/
|
||||||
protected $capture_factory;
|
protected $checkout_helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PayUponInvoice constructor.
|
* PayUponInvoice constructor.
|
||||||
|
@ -137,7 +136,7 @@ class PayUponInvoice {
|
||||||
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
|
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
|
||||||
* @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
|
* @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
|
||||||
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
||||||
* @param CaptureFactory $capture_factory The capture factory.
|
* @param CheckoutHelper $checkout_helper The checkout helper.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $module_url,
|
string $module_url,
|
||||||
|
@ -152,7 +151,7 @@ class PayUponInvoice {
|
||||||
string $current_ppcp_settings_page_id,
|
string $current_ppcp_settings_page_id,
|
||||||
PayUponInvoiceProductStatus $pui_product_status,
|
PayUponInvoiceProductStatus $pui_product_status,
|
||||||
PayUponInvoiceHelper $pui_helper,
|
PayUponInvoiceHelper $pui_helper,
|
||||||
CaptureFactory $capture_factory
|
CheckoutHelper $checkout_helper
|
||||||
) {
|
) {
|
||||||
$this->module_url = $module_url;
|
$this->module_url = $module_url;
|
||||||
$this->fraud_net = $fraud_net;
|
$this->fraud_net = $fraud_net;
|
||||||
|
@ -166,7 +165,7 @@ class PayUponInvoice {
|
||||||
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
|
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
|
||||||
$this->pui_product_status = $pui_product_status;
|
$this->pui_product_status = $pui_product_status;
|
||||||
$this->pui_helper = $pui_helper;
|
$this->pui_helper = $pui_helper;
|
||||||
$this->capture_factory = $capture_factory;
|
$this->checkout_helper = $checkout_helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue