Add process payment for bancontact gateway (WIP)

This commit is contained in:
Emili Castells Guasch 2024-08-09 17:21:38 +02:00
parent a65d4fb2dc
commit 633ae1aed0
4 changed files with 123 additions and 15 deletions

View file

@ -241,10 +241,11 @@ return array(
$bn_code
);
},
'api.endpoint.orders' => static function (ContainerInterface $container): Orders {
'api.endpoint.orders' => static function ( ContainerInterface $container ): Orders {
return new Orders(
$container->get( 'api.host' ),
$container->get( 'api.bearer' )
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use Psr\Log\LoggerInterface;
use RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WP_Error;
@ -19,6 +20,8 @@ use WP_Error;
*/
class Orders {
use RequestTrait;
/**
* The host.
*
@ -33,29 +36,47 @@ class Orders {
*/
private $bearer;
/**
* The logger.
*
* @var LoggerInterface
*/
private $logger;
/**
* Orders constructor.
*
* @param string $host
* @param Bearer $bearer
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
string $host,
Bearer $bearer
Bearer $bearer,
LoggerInterface $logger
) {
$this->host = $host;
$this->host = $host;
$this->bearer = $bearer;
$this->logger = $logger;
}
public function create(array $request_body, array $headers = array()): array {
/**
* Creates a PayPal order.
*
* @param array $request_body The request body.
* @param array $headers The request headers.
* @return array
* @throws RuntimeException If something is wrong with the request.
*/
public function create( array $request_body, array $headers = array() ): array {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
$default_headers = array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Content-Type' => 'application/json',
);
$headers = array_merge(
$headers = array_merge(
$default_headers,
$headers
);
@ -66,7 +87,7 @@ class Orders {
'body' => wp_json_encode( $request_body ),
);
$response = wp_remote_get( $url, $args );
$response = $this->request( $url, $args );
if ( $response instanceof WP_Error ) {
throw new RuntimeException( $response->get_error_message() );
}