mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add multibanco gateway (WIP)
This commit is contained in:
parent
2699629b90
commit
ec06ea5f27
6 changed files with 412 additions and 0 deletions
|
@ -95,6 +95,47 @@ class Orders {
|
|||
throw new RuntimeException( $response->get_error_message() );
|
||||
}
|
||||
|
||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
|
||||
throw new PayPalApiException(
|
||||
json_decode( $response['body'] ),
|
||||
$status_code
|
||||
);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms the given order.
|
||||
*
|
||||
* @link https://developer.paypal.com/docs/api/orders/v2/#orders_confirm
|
||||
*
|
||||
* @param array $request_body The request body.
|
||||
* @param string $id PayPal order ID.
|
||||
* @return array
|
||||
* @throws RuntimeException If something went wrong with the request.
|
||||
* @throws PayPalApiException If something went wrong with the PayPal API request.
|
||||
*/
|
||||
public function confirm_payment_source(array $request_body, string $id): array {
|
||||
$bearer = $this->bearer->bearer();
|
||||
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id .'/confirm-payment-source';
|
||||
|
||||
$args = array(
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'Authorization' => 'Bearer ' . $bearer->token(),
|
||||
'Content-Type' => 'application/json',
|
||||
'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
|
||||
),
|
||||
'body' => wp_json_encode( $request_body ),
|
||||
);
|
||||
|
||||
$response = $this->request( $url, $args );
|
||||
if ( $response instanceof WP_Error ) {
|
||||
throw new RuntimeException( $response->get_error_message() );
|
||||
}
|
||||
|
||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( $status_code !== 200 ) {
|
||||
throw new PayPalApiException(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue