For now pass the intent type as dependency

This commit is contained in:
Mészáros Róbert 2020-04-13 11:52:24 +03:00
parent f4fd1d8b7d
commit 35afcb5d2c
2 changed files with 13 additions and 3 deletions

View file

@ -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 {

View file

@ -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();