Skip to content

Commit

Permalink
payment validation
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Sep 1, 2022
1 parent e45593c commit 5031622
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/checkout.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 26 additions & 19 deletions includes/class-depay-wc-payments-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,39 @@ public function track_payment($request) {
));
}

$post = wp_remote_post("https://public.depay.com/payments", [
"blockchain" => $accepted_payment->blockchain,
"receiver" => $accepted_payment->receiver,
"token" => $accepted_payment->token,
"amount" => $amount,
"confirmations" => $required_confirmations,
"transaction" => $transaction_id,
"sender" => $request->get_param('sender'),
"nonce" => $request->get_param('nonce'),
"after_block" => $request->get_param('after_block'),
"uuid" => $tracking_uuid,
"callback" => get_site_url(null, 'index.php?rest_route=/depay/wc/validate'),
"forward_to" => $order->get_checkout_order_received_url(),
"forward_on_failure" => false,
"fee_amount" => $fee_amount,
"fee_receiver" => '0x9Db58B260EfAa2d6a94bEb7E219d073dF51cc7Bb'
]);
$post = wp_remote_post("https://public.depay.com/payments",
array(
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'body' => json_encode([
'blockchain' => $accepted_payment->blockchain,
'receiver' => $accepted_payment->receiver,
'token' => $accepted_payment->token,
'amount' => $amount,
'confirmations' => $required_confirmations,
'transaction' => $transaction_id,
'sender' => $request->get_param('sender'),
'nonce' => $request->get_param('nonce'),
'after_block' => $request->get_param('after_block'),
'uuid' => $tracking_uuid,
'callback' => get_site_url(null, 'index.php?rest_route=/depay/wc/validate'),
'forward_to' => $order->get_checkout_order_received_url(),
'forward_on_failure' => false,
'fee_amount' => $fee_amount,
'fee_receiver' => '0x9Db58B260EfAa2d6a94bEb7E219d073dF51cc7Bb'
]),
'method' => 'POST',
'data_format' => 'body'
)
);

$response = new WP_REST_Response();
$response = rest_ensure_response("{}");
if(!is_wp_error($post) && (wp_remote_retrieve_response_code($post) == 200 || wp_remote_retrieve_response_code($post) == 201)) {
$response->set_status(200);
} else {
$response->set_status(500);
}

return rest_ensure_response($response);
return $response;
}

public function validate_payment($request) {
Expand Down
1 change: 1 addition & 0 deletions src/admin/AdminTransactionsPage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions src/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ window.addEventListener( 'hashchange', async()=> {
closed: ()=>{ window.jQuery('form.woocommerce-checkout').removeClass( 'processing' ).unblock() },
track: {
method: (payment)=>{
return wp.apiRequest({
path: `/depay/wc/checkouts/${checkoutId}/track`,
method: 'POST',
data: payment
}).then((result)=>{ status: result ? 200 : 0 })
return new Promise((resolve, reject)=>{
wp.apiRequest({
path: `/depay/wc/checkouts/${checkoutId}/track`,
method: 'POST',
data: payment
})
.done((result)=>resolve({ status: 200 }))
.fail((request, status)=>reject(status))
})
}
}
})
Expand Down

0 comments on commit 5031622

Please sign in to comment.