diff --git a/modules.local/ppcp-api-client/services.php b/modules.local/ppcp-api-client/services.php index 4cff301cc..9a0e7f536 100644 --- a/modules.local/ppcp-api-client/services.php +++ b/modules.local/ppcp-api-client/services.php @@ -1,4 +1,5 @@ get('api.secret') ); }, - 'api.endpoint.payments' => function (ContainerInterface $container) : PaymentsEndpoint { + 'api.endpoint.payments' => function (ContainerInterface $container): PaymentsEndpoint { $authorizationFactory = $container->get('api.factory.authorization'); $errorResponseFactory = $container->get('api.factory.response-error'); @@ -59,7 +61,7 @@ return [ $errorResponseFactory ); }, - 'api.endpoint.order' => function (ContainerInterface $container) : OrderEndpoint { + 'api.endpoint.order' => function (ContainerInterface $container): OrderEndpoint { $orderFactory = $container->get('api.factory.order'); $patchCollectionFactory = $container->get('api.factory.patch-collection-factory'); $errorResponseFactory = $container->get('api.factory.response-error'); @@ -110,12 +112,15 @@ return [ $payeeFactory = $container->get('api.factory.payee'); $itemFactory = $container->get('api.factory.item'); $shippingFactory = $container->get('api.factory.shipping'); + $paymentsFactory = $container->get('api.factory.payments'); + return new PurchaseUnitFactory( $amountFactory, $payeeRepository, $payeeFactory, $itemFactory, - $shippingFactory + $shippingFactory, + $paymentsFactory ); }, 'api.factory.patch-collection-factory' => function (ContainerInterface $container) @@ -151,7 +156,11 @@ return [ $payerFactory = $container->get('api.factory.payer'); return new OrderFactory($purchaseUnitFactory, $payerFactory); }, - 'api.factory.authorization' => function (ContainerInterface $container) : AuthorizationsFactory { - return new AuthorizationsFactory(); + 'api.factory.payments' => function (ContainerInterface $container): PaymentsFactory { + $authorizationFactory = $container->get('api.factory.authorization'); + return new PaymentsFactory($authorizationFactory); + }, + 'api.factory.authorization' => function (ContainerInterface $container): AuthorizationFactory { + return new AuthorizationFactory(); }, ]; diff --git a/modules.local/ppcp-api-client/src/Entity/Payments.php b/modules.local/ppcp-api-client/src/Entity/Payments.php new file mode 100644 index 000000000..7a81141da --- /dev/null +++ b/modules.local/ppcp-api-client/src/Entity/Payments.php @@ -0,0 +1,26 @@ +authorizations = $authorizations; + } + + public function toArray() + { + return [ + + ]; + } + + public function authorizations() : array + { + return $this->authorizations; + } +} diff --git a/modules.local/ppcp-api-client/src/Entity/PurchaseUnit.php b/modules.local/ppcp-api-client/src/Entity/PurchaseUnit.php index c1023ce6b..dbbab80ff 100644 --- a/modules.local/ppcp-api-client/src/Entity/PurchaseUnit.php +++ b/modules.local/ppcp-api-client/src/Entity/PurchaseUnit.php @@ -1,4 +1,5 @@ amount = $amount; @@ -43,6 +47,7 @@ class PurchaseUnit $this->customId = $customId; $this->invoiceId = $invoiceId; $this->softDescriptor = $softDescriptor; + $this->payments = $payments; } public function amount() : Amount @@ -114,6 +119,10 @@ class PurchaseUnit $purchaseUnit['payee'] = $this->payee()->toArray(); } + if ($this->payments()) { + $purchaseUnit['payments'] = $this->payments()->toArray(); + } + if ($this->shipping()) { $purchaseUnit['shipping'] = $this->shipping()->toArray(); } diff --git a/modules.local/ppcp-api-client/src/Factory/PaymentsFactory.php b/modules.local/ppcp-api-client/src/Factory/PaymentsFactory.php new file mode 100644 index 000000000..3263621bd --- /dev/null +++ b/modules.local/ppcp-api-client/src/Factory/PaymentsFactory.php @@ -0,0 +1,32 @@ +authorizationsFactory = $authorizationsFactory; + } + + public function fromPayPalResponse(\stdClass $data) + { + $authorizations = array_map( + function (\stdClass $authorization): Authorization { + return $this->authorizationsFactory->fromPayPalRequest($authorization); + }, + $data->authorizations + ); + $payments = new Payments($authorizations); + return $payments; + } +} diff --git a/modules.local/ppcp-api-client/src/Factory/PurchaseUnitFactory.php b/modules.local/ppcp-api-client/src/Factory/PurchaseUnitFactory.php index 2fea9b2ff..6f63bc59e 100644 --- a/modules.local/ppcp-api-client/src/Factory/PurchaseUnitFactory.php +++ b/modules.local/ppcp-api-client/src/Factory/PurchaseUnitFactory.php @@ -1,4 +1,5 @@ amountFactory = $amountFactory; @@ -29,6 +33,7 @@ class PurchaseUnitFactory $this->payeeFactory = $payeeFactory; $this->itemFactory = $itemFactory; $this->shippingFactory = $shippingFactory; + $this->$paymentsFactory = $paymentsFactory; } public function fromWcOrder(\WC_Order $order) : PurchaseUnit @@ -129,7 +134,11 @@ class PurchaseUnitFactory $shipping = isset($data->shipping) ? $this->shippingFactory->fromPayPalResponse($data->shipping) : null; - return new PurchaseUnit( + $payments = isset($data->payments) ? + $this->paymentsFactory->fromPayPalResponse($data->payments) : + null; + + $purchaseUnit = new PurchaseUnit( $amount, $items, $shipping, @@ -138,7 +147,9 @@ class PurchaseUnitFactory $payee, $customId, $invoiceId, - $softDescriptor + $softDescriptor, + $payments ); + return $purchaseUnit; } }