mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
41 lines
1.8 KiB
PHP
41 lines
1.8 KiB
PHP
|
<?php
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace Inpsyde\PayPalCommerce\Button;
|
||
|
|
||
|
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
|
||
|
use Dhii\Data\Container\ContainerInterface;
|
||
|
use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint;
|
||
|
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
|
||
|
use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
|
||
|
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
||
|
|
||
|
return [
|
||
|
'button.smart-button' => function(ContainerInterface $container) {
|
||
|
$isSandbox = true;
|
||
|
return new SmartButton($container->get('button.url'), $isSandbox);
|
||
|
},
|
||
|
'button.url' => function(ContainerInterface $container) : string {
|
||
|
return plugins_url('/modules/ppcp-button/', dirname(__FILE__, 3) . '/woocommerce-paypal-commerce-gateway.php');
|
||
|
},
|
||
|
'button.request-data' => function(ContainerInterface $container) : RequestData {
|
||
|
return new RequestData();
|
||
|
},
|
||
|
'button.endpoint.change-cart' => function(ContainerInterface $container) : ChangeCartEndpoint {
|
||
|
if (! \WC()->cart) {
|
||
|
throw new RuntimeException('cant initialize endpoint at this moment');
|
||
|
}
|
||
|
$cart = WC()->cart;
|
||
|
$shipping = WC()->shipping();
|
||
|
$requestData = $container->get('button.request-data');
|
||
|
$repository = $container->get('api.cart-repository');
|
||
|
return new ChangeCartEndpoint($cart, $shipping, $requestData, $repository);
|
||
|
},
|
||
|
'button.endpoint.create-order' => function(ContainerInterface $container) : CreateOrderEndpoint {
|
||
|
$requestData = $container->get('button.request-data');
|
||
|
$repository = $container->get('api.cart-repository');
|
||
|
$apiClient = $container->get('api.endpoint.order');
|
||
|
return new CreateOrderEndpoint($requestData, $repository, $apiClient);
|
||
|
}
|
||
|
];
|