-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Apple Pay as express payment method (#9)
- Loading branch information
1 parent
207997b
commit 317a1b2
Showing
22 changed files
with
1,205 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
add_action('rest_api_init', function () { | ||
register_rest_route('betterpayment', 'apple-pay-session', array( | ||
'methods' => 'POST', | ||
'callback' => 'fetch_apple_pay_session', | ||
'permission_callback' => '__return_true', // Adjust permissions as needed | ||
)); | ||
}); | ||
|
||
function fetch_apple_pay_session(): WP_REST_Response { | ||
$url = Config_Reader::get_api_url() . '/db_apple_pay_merchants'; | ||
|
||
$headers = [ | ||
'Content-Type' => 'application/json', | ||
'Authorization' => 'Basic ' . base64_encode( Config_Reader::get_api_key() . ':' . Config_Reader::get_outgoing_key()) | ||
]; | ||
|
||
$body = wp_json_encode([ | ||
'initiative_context' => parse_url(home_url(), PHP_URL_HOST), | ||
]); | ||
|
||
$response = wp_remote_post( $url, [ | ||
'headers' => $headers, | ||
'body' => $body, | ||
]); | ||
|
||
if ( 200 === wp_remote_retrieve_response_code( $response ) ) { | ||
$responseBody = json_decode( wp_remote_retrieve_body( $response ), true ); | ||
|
||
return new WP_REST_Response($responseBody, 200); | ||
} | ||
else { | ||
return new WP_REST_Response(wp_remote_retrieve_body($response), wp_remote_retrieve_response_code($response)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
add_action('rest_api_init', function () { | ||
register_rest_route('betterpayment', 'payment', array( | ||
'methods' => 'POST', | ||
'callback' => 'payment', | ||
'permission_callback' => '__return_true', // Adjust permissions as needed | ||
)); | ||
}); | ||
|
||
// Only used for Apple Pay | ||
function payment(WP_REST_Request $request): WP_REST_Response { | ||
$url = Config_Reader::get_api_url() . '/rest/payment'; | ||
$body = $request->get_body_params(); | ||
|
||
// Add the payment type to the body | ||
$body['payment_type'] = 'applepay'; | ||
|
||
$headers = [ | ||
'Content-Type' => 'application/json', | ||
'Authorization' => 'Basic ' . base64_encode( Config_Reader::get_api_key() . ':' . Config_Reader::get_outgoing_key() ) | ||
]; | ||
|
||
$response = wp_remote_post( $url, [ | ||
'headers' => $headers, | ||
'body' => wp_json_encode($body), | ||
] ); | ||
|
||
return new WP_REST_Response(wp_remote_retrieve_body($response), wp_remote_retrieve_response_code($response)); | ||
} |
File renamed without changes.
Oops, something went wrong.