mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
move bn code into session
This commit is contained in:
parent
e4a4ec3acb
commit
68866f8ef2
3 changed files with 41 additions and 3 deletions
|
@ -92,7 +92,8 @@ return [
|
|||
$repository = $container->get('api.repository.cart');
|
||||
$apiClient = $container->get('api.endpoint.order');
|
||||
$payerFactory = $container->get('api.factory.payer');
|
||||
return new CreateOrderEndpoint($requestData, $repository, $apiClient, $payerFactory);
|
||||
$sessionHandler = $container->get('session.handler');
|
||||
return new CreateOrderEndpoint($requestData, $repository, $apiClient, $payerFactory, $sessionHandler);
|
||||
},
|
||||
'button.endpoint.approve-order' => static function (ContainerInterface $container): ApproveOrderEndpoint {
|
||||
$requestData = $container->get('button.request-data');
|
||||
|
|
|
@ -8,6 +8,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
|||
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
||||
|
||||
class CreateOrderEndpoint implements EndpointInterface
|
||||
{
|
||||
|
@ -18,17 +19,20 @@ class CreateOrderEndpoint implements EndpointInterface
|
|||
private $repository;
|
||||
private $apiEndpoint;
|
||||
private $payerFactory;
|
||||
private $sessionHandler;
|
||||
public function __construct(
|
||||
RequestData $requestData,
|
||||
CartRepository $repository,
|
||||
OrderEndpoint $apiEndpoint,
|
||||
PayerFactory $payerFactory
|
||||
PayerFactory $payerFactory,
|
||||
SessionHandler $sessionHandler
|
||||
) {
|
||||
|
||||
$this->requestData = $requestData;
|
||||
$this->repository = $repository;
|
||||
$this->apiEndpoint = $apiEndpoint;
|
||||
$this->payerFactory = $payerFactory;
|
||||
$this->sessionHandler = $sessionHandler;
|
||||
}
|
||||
|
||||
public static function nonce(): string
|
||||
|
@ -53,9 +57,12 @@ class CreateOrderEndpoint implements EndpointInterface
|
|||
$payer = $this->payerFactory->fromPayPalResponse(json_decode(json_encode($data['payer'])));
|
||||
}
|
||||
$bnCode = isset($data['bn_code']) ? (string) $data['bn_code'] : '';
|
||||
if ($bnCode) {
|
||||
$this->sessionHandler->replaceBnCode($bnCode);
|
||||
$this->apiEndpoint->withBnCode($bnCode);
|
||||
}
|
||||
$order = $this->apiEndpoint->createForPurchaseUnits(
|
||||
$purchaseUnits,
|
||||
$bnCode,
|
||||
$payer
|
||||
);
|
||||
wp_send_json_success($order->toArray());
|
||||
|
|
|
@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway;
|
||||
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use Inpsyde\Woocommerce\Logging\Logger\NullLogger;
|
||||
use Inpsyde\Woocommerce\Logging\Logger\WooCommerceLogger;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
@ -32,6 +35,33 @@ return [
|
|||
$settings = $container->get('wcgateway.settings');
|
||||
return $settings->has('client_secret') ? (string) $settings->get('client_secret') : '';
|
||||
},
|
||||
'api.endpoint.order' => static function (ContainerInterface $container): OrderEndpoint {
|
||||
$orderFactory = $container->get('api.factory.order');
|
||||
$patchCollectionFactory = $container->get('api.factory.patch-collection-factory');
|
||||
$logger = $container->get('woocommerce.logger.woocommerce');
|
||||
/**
|
||||
* @var SessionHandler $sessionHandler
|
||||
*/
|
||||
$sessionHandler = $container->get('session.handler');
|
||||
$bnCode = $sessionHandler->bnCode();
|
||||
|
||||
/**
|
||||
* @var Settings $settings
|
||||
*/
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
$intent = $settings->has('intent') && strtoupper((string) $settings->get('intent')) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
|
||||
$applicationContextRepository = $container->get('api.repository.application-context');
|
||||
return new OrderEndpoint(
|
||||
$container->get('api.host'),
|
||||
$container->get('api.bearer'),
|
||||
$orderFactory,
|
||||
$patchCollectionFactory,
|
||||
$intent,
|
||||
$logger,
|
||||
$applicationContextRepository,
|
||||
$bnCode
|
||||
);
|
||||
},
|
||||
'woocommerce.logger.woocommerce' => function (ContainerInterface $container): LoggerInterface {
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
if (! $settings->has('logging_enabled') || ! $settings->get('logging_enabled')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue