1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

setup callback logic

This commit is contained in:
cnohall 2024-09-05 14:29:16 +09:00
parent 3e5d598d53
commit 886d1af824
3 changed files with 51 additions and 5 deletions

View File

@ -52,10 +52,58 @@ class Blockonomics implements MethodInterface
{
}
public function doCurlCall($url, $post_content = '')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($post_content) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_content);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $this->driver_class->api_key,
'Content-type: application/x-www-form-urlencoded',
]);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
echo "Error:" . curl_error($ch);
}
$responseObj = json_decode($contents);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ($status != 200) {
echo "ERROR: " . $status . ' ' . $responseObj->message;
} else {
echo "Success: " . $status;
echo json_encode($responseObj);
}
return $responseObj;
}
public function setCallbackUrl()
{
$GET_CALLBACKS_URL = 'https://www.blockonomics.co/api/address?&no_balance=true&only_xpub=true&get_callback=true';
$SET_CALLBACK_URL = 'https://www.blockonomics.co/api/update_callback';
$get_callback_response = $this->doCurlCall($GET_CALLBACKS_URL);
$callback_url = $this->driver_class->callback_url;
$xpub = $get_callback_response[0]->address;
$post_content = '{"callback": "' . $callback_url . '", "xpub": "' . $xpub . '"}';
$responseObj = $this->doCurlCall($SET_CALLBACK_URL, $post_content);
return $responseObj;
}
public function getBTCAddress()
{
$api_key = $this->driver_class->api_key;
$url = 'https://www.blockonomics.co/api/new_address';
// TODO: remove ?reset=1 before marking PR as ready
$url = 'https://www.blockonomics.co/api/new_address?reset=1';
$ch = curl_init();
@ -113,12 +161,12 @@ class Blockonomics implements MethodInterface
$data['btc_address'] = $this->getBTCAddress();
$data['invoice_id'] = $this->invoice_id;
$data['end_time'] = $this->getTenMinutesCountDownEndTime();
$data['callback_url'] = $this->setCallbackUrl();
return render('gateways.blockonomics.pay', $data);
}
public function paymentResponse(PaymentResponseRequest $request)
{
$request->validate([
'payment_hash' => ['required'],
'amount' => ['required'],

View File

@ -48,7 +48,6 @@ class BlockonomicsPaymentDriver extends BaseDriver
public $BASE_URL = 'https://www.blockonomics.co';
public $NEW_ADDRESS_URL = 'https://www.blockonomics.co/api/new_address';
public $PRICE_URL = 'https://www.blockonomics.co/api/price';
public $SET_CALLBACK_URL = 'https://www.blockonomics.co/api/update_callback';
public function init()
{

View File

@ -24,8 +24,7 @@ class PaymentLibrariesSeeder extends Seeder
{
Model::unguard();
// TODO: use get callbacks API to get the callback URL
$callbackUrl = config('ninja.app_url') . '/payment/callback';
$callbackUrl = config('ninja.app_url') . '/client/payments/process/?secret=';
$callbackSecret = md5(uniqid(rand(), true));
$blockonomics_fields = "{
\"apiKey\": \"\",