mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
For now pass the intent type as dependency
This commit is contained in:
parent
f4fd1d8b7d
commit
35afcb5d2c
2 changed files with 13 additions and 3 deletions
|
@ -46,11 +46,17 @@ return [
|
|||
'api.endpoint.order' => function (ContainerInterface $container) : OrderEndpoint {
|
||||
$orderFactory = $container->get('api.factory.order');
|
||||
$patchCollectionFactory = $container->get('api.factory.patch-collection-factory');
|
||||
|
||||
// TODO: get the settings using the class
|
||||
// Using it now throws a maximum nested error because they share the same dependency
|
||||
$intent = strtoupper(get_option('woocommerce_ppcp-gateway_settings')['intent']);
|
||||
|
||||
return new OrderEndpoint(
|
||||
$container->get('api.host'),
|
||||
$container->get('api.bearer'),
|
||||
$orderFactory,
|
||||
$patchCollectionFactory
|
||||
$patchCollectionFactory,
|
||||
$intent
|
||||
);
|
||||
},
|
||||
'api.cart-repository' => function (ContainerInterface $container) : CartRepository {
|
||||
|
|
|
@ -18,24 +18,28 @@ class OrderEndpoint
|
|||
private $bearer;
|
||||
private $orderFactory;
|
||||
private $patchCollectionFactory;
|
||||
private $intent;
|
||||
|
||||
public function __construct(
|
||||
string $host,
|
||||
Bearer $bearer,
|
||||
OrderFactory $orderFactory,
|
||||
PatchCollectionFactory $patchCollectionFactory
|
||||
PatchCollectionFactory $patchCollectionFactory,
|
||||
string $intent
|
||||
) {
|
||||
|
||||
$this->host = $host;
|
||||
$this->bearer = $bearer;
|
||||
$this->orderFactory = $orderFactory;
|
||||
$this->patchCollectionFactory = $patchCollectionFactory;
|
||||
$this->intent = $intent;
|
||||
}
|
||||
|
||||
public function createForPurchaseUnits(PurchaseUnit ...$items) : Order
|
||||
{
|
||||
$bearer = $this->bearer->bearer();
|
||||
$data = [
|
||||
'intent' => 'CAPTURE',
|
||||
'intent' => $this->intent, // TODO: read this from the global settings
|
||||
'purchase_units' => array_map(
|
||||
function (PurchaseUnit $item) : array {
|
||||
return $item->toArray();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue