Merge pull request #10308 from cnohall/update-blockonomics-driver
Update: Update Blockonomics driver
This commit is contained in:
commit
87a71f87c9
|
|
@ -108,7 +108,7 @@ class Gateway extends StaticModel
|
||||||
} elseif ($this->id == 63) {
|
} elseif ($this->id == 63) {
|
||||||
$link = 'https://rotessa.com';
|
$link = 'https://rotessa.com';
|
||||||
} elseif ($this->id == 64) {
|
} elseif ($this->id == 64) {
|
||||||
$link = 'https://blockonomics.co';
|
$link = 'https://help.blockonomics.co/a/solutions/articles/33000291849';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $link;
|
return $link;
|
||||||
|
|
|
||||||
|
|
@ -47,24 +47,36 @@ class Blockonomics implements LivewireMethodInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getBTCAddress(): string
|
public function getBTCAddress(): array
|
||||||
{
|
{
|
||||||
$api_key = $this->blockonomics->company_gateway->getConfigField('apiKey');
|
$api_key = $this->blockonomics->company_gateway->getConfigField('apiKey');
|
||||||
|
|
||||||
|
if (!$api_key) {
|
||||||
|
return ['success' => false, 'message' => 'Please enter a valid API key'];
|
||||||
|
}
|
||||||
|
|
||||||
// $params = config('ninja.environment') == 'development' ? '?reset=1' : '';
|
// $params = config('ninja.environment') == 'development' ? '?reset=1' : '';
|
||||||
$url = 'https://www.blockonomics.co/api/new_address';
|
$url = 'https://www.blockonomics.co/api/new_address';
|
||||||
|
|
||||||
$r = Http::withToken($api_key)
|
$response = Http::withToken($api_key)
|
||||||
->post($url, []);
|
->post($url, []);
|
||||||
|
|
||||||
nlog($r->body());
|
nlog($response->body());
|
||||||
|
|
||||||
if ($r->successful()) {
|
if ($response->status() == 401) {
|
||||||
return $r->object()->address ?? 'Something went wrong';
|
return ['success' => false, 'message' => 'API Key is incorrect'];
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
|
if (isset($response->object()->address)) {
|
||||||
|
return ['success' => true, 'address' => $response->object()->address];
|
||||||
|
} else {
|
||||||
|
return ['success' => false, 'message' => 'Address not returned'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ['success' => false, 'message' => "Could not generate new address (This may be a temporary error. Please try again). \n\n<br><br> If this continues, please ask website administrator to check blockonomics registered email address for error messages"];
|
||||||
}
|
}
|
||||||
|
return ['success' => false, 'message' => 'Something went wrong'];
|
||||||
return $r->object()->message ?? 'Something went wrong';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBTCPrice()
|
public function getBTCPrice()
|
||||||
|
|
@ -81,6 +93,10 @@ class Blockonomics implements LivewireMethodInterface
|
||||||
|
|
||||||
$btc_price = $this->getBTCPrice();
|
$btc_price = $this->getBTCPrice();
|
||||||
$btc_address = $this->getBTCAddress();
|
$btc_address = $this->getBTCAddress();
|
||||||
|
$data['error'] = null;
|
||||||
|
if (!$btc_address['success']) {
|
||||||
|
$data['error'] = $btc_address['message'];
|
||||||
|
}
|
||||||
$fiat_amount = $data['total']['amount_with_fee'];
|
$fiat_amount = $data['total']['amount_with_fee'];
|
||||||
$btc_amount = $fiat_amount / $btc_price;
|
$btc_amount = $fiat_amount / $btc_price;
|
||||||
$_invoice = collect($this->blockonomics->payment_hash->data->invoices)->first();
|
$_invoice = collect($this->blockonomics->payment_hash->data->invoices)->first();
|
||||||
|
|
@ -89,7 +105,7 @@ class Blockonomics implements LivewireMethodInterface
|
||||||
$data['amount'] = $fiat_amount;
|
$data['amount'] = $fiat_amount;
|
||||||
$data['currency'] = $this->blockonomics->client->getCurrencyCode();
|
$data['currency'] = $this->blockonomics->client->getCurrencyCode();
|
||||||
$data['btc_amount'] = number_format($btc_amount, 10, '.', '');
|
$data['btc_amount'] = number_format($btc_amount, 10, '.', '');
|
||||||
$data['btc_address'] = $btc_address;
|
$data['btc_address'] = $btc_address['address'] ?? '';
|
||||||
$data['btc_price'] = $btc_price;
|
$data['btc_price'] = $btc_price;
|
||||||
$data['invoice_number'] = $_invoice->invoice_number;
|
$data['invoice_number'] = $_invoice->invoice_number;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,4 +143,22 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
||||||
$this->setPaymentMethod(GatewayType::CRYPTO);
|
$this->setPaymentMethod(GatewayType::CRYPTO);
|
||||||
return $this->payment_method->refund($payment, $amount); //this is your custom implementation from here
|
return $this->payment_method->refund($payment, $amount); //this is your custom implementation from here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function auth(): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// TODO: Add check /api/new_address?reset=1 to see if the API key is valid
|
||||||
|
$this->company_gateway->getConfigField('apiKey');
|
||||||
|
$url = $this->NEW_ADDRESS_URL . '?reset=1';
|
||||||
|
$response = Http::withToken($api_key)
|
||||||
|
->post($url, []);
|
||||||
|
if($response->successful()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use App\Models\GatewayType;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class PaymentLibrariesSeeder extends Seeder
|
class PaymentLibrariesSeeder extends Seeder
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +25,9 @@ class PaymentLibrariesSeeder extends Seeder
|
||||||
{
|
{
|
||||||
Model::unguard();
|
Model::unguard();
|
||||||
|
|
||||||
|
// Generate a random callback secret for Blockonomics users
|
||||||
|
$callbackSecret = Str::random(32);
|
||||||
|
|
||||||
$gateways = [
|
$gateways = [
|
||||||
['id' => 1, 'name' => 'Authorize.Net', 'provider' => 'Authorize', 'sort_order' => 5, 'key' => '3b6621f970ab18887c4f6dca78d3f8bb', 'fields' => '{"apiLoginId":"","transactionKey":"","testMode":false,"developerMode":false,"liveEndpoint":"https:\/\/api2.authorize.net\/xml\/v1\/request.api","developerEndpoint":"https:\/\/apitest.authorize.net\/xml\/v1\/request.api"}
|
['id' => 1, 'name' => 'Authorize.Net', 'provider' => 'Authorize', 'sort_order' => 5, 'key' => '3b6621f970ab18887c4f6dca78d3f8bb', 'fields' => '{"apiLoginId":"","transactionKey":"","testMode":false,"developerMode":false,"liveEndpoint":"https:\/\/api2.authorize.net\/xml\/v1\/request.api","developerEndpoint":"https:\/\/apitest.authorize.net\/xml\/v1\/request.api"}
|
||||||
'],
|
'],
|
||||||
|
|
@ -90,7 +94,7 @@ class PaymentLibrariesSeeder extends Seeder
|
||||||
['id' => 62, 'name' => 'BTCPay', 'provider' => 'BTCPay', 'key' => 'vpyfbmdrkqcicpkjqdusgjfluebftuva', 'fields' => '{"btcpayUrl":"", "apiKey":"", "storeId":"", "webhookSecret":""}'],
|
['id' => 62, 'name' => 'BTCPay', 'provider' => 'BTCPay', 'key' => 'vpyfbmdrkqcicpkjqdusgjfluebftuva', 'fields' => '{"btcpayUrl":"", "apiKey":"", "storeId":"", "webhookSecret":""}'],
|
||||||
['id' => 63, 'name' => 'Rotessa', 'is_offsite' => false, 'sort_order' => 22, 'provider' => 'Rotessa', 'key' => '91be24c7b792230bced33e930ac61676', 'fields' => '{"apiKey":"", "testMode":false}'],
|
['id' => 63, 'name' => 'Rotessa', 'is_offsite' => false, 'sort_order' => 22, 'provider' => 'Rotessa', 'key' => '91be24c7b792230bced33e930ac61676', 'fields' => '{"apiKey":"", "testMode":false}'],
|
||||||
['id' => 64, 'name' => 'CBA PowerBoard', 'is_offsite' => false, 'sort_order' => 26, 'provider' => 'CBAPowerBoard', 'key' => 'b67581d804dbad1743b61c57285142ad', 'fields' => '{"publicKey":"", "secretKey":"", "testMode":false, "gatewayId":"", "amex":false, "ausbc":false, "discover":false, "japcb":false, "laser":false, "mastercard":true, "solo":false, "visa":true, "visa_white":false}'],
|
['id' => 64, 'name' => 'CBA PowerBoard', 'is_offsite' => false, 'sort_order' => 26, 'provider' => 'CBAPowerBoard', 'key' => 'b67581d804dbad1743b61c57285142ad', 'fields' => '{"publicKey":"", "secretKey":"", "testMode":false, "gatewayId":"", "amex":false, "ausbc":false, "discover":false, "japcb":false, "laser":false, "mastercard":true, "solo":false, "visa":true, "visa_white":false}'],
|
||||||
['id' => 65, 'name' => 'Blockonomics', 'is_offsite' => false, 'sort_order' => 27, 'provider' => 'Blockonomics', 'key' => 'wbhf02us6owgo7p4nfjd0ymssdshks4d', 'fields' => '{"apiKey":"", "callbackSecret":""}'],
|
['id' => 65, 'name' => 'Blockonomics', 'is_offsite' => false, 'sort_order' => 27, 'provider' => 'Blockonomics', 'key' => 'wbhf02us6owgo7p4nfjd0ymssdshks4d', 'fields' => '{"apiKey":"", "callbackSecret":"' . $callbackSecret . '"}'],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($gateways as $gateway) {
|
foreach ($gateways as $gateway) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,11 @@
|
||||||
<meta name="btc_amount" content="{{ $btc_amount }}" />
|
<meta name="btc_amount" content="{{ $btc_amount }}" />
|
||||||
<meta name="btc_address" content="{{ $btc_address }}" />
|
<meta name="btc_address" content="{{ $btc_address }}" />
|
||||||
<meta name="currency" content="{{ $currency }}" />
|
<meta name="currency" content="{{ $currency }}" />
|
||||||
|
<meta name="error" content="{{ $error }}" />
|
||||||
|
|
||||||
|
@if ($error)
|
||||||
|
<div class="alert alert-danger my-10 mx-4">{!! $error !!}</div>
|
||||||
|
@else
|
||||||
<div class="alert alert-failure mb-4" hidden id="errors"></div>
|
<div class="alert alert-failure mb-4" hidden id="errors"></div>
|
||||||
<div class="blockonomics-payment-wrapper">
|
<div class="blockonomics-payment-wrapper">
|
||||||
<div class="initial-state">
|
<div class="initial-state">
|
||||||
|
|
@ -43,6 +47,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
|
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
|
||||||
@csrf
|
@csrf
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue