1
0
Fork 0

feat: send_request of bitcart

This commit is contained in:
Konrad Geletey 2024-02-23 11:48:16 +03:00
parent 81d28506fd
commit 7951058097
Signed by: kglt
GPG key ID: 386DEE24B60BD996
2 changed files with 106 additions and 50 deletions

106
BitCart.php Normal file
View file

@ -0,0 +1,106 @@
<?php
// https://github.com/bitcart/whmcs-plugin/blob/master/modules/gateways/bitcartcheckout.php
// https://github.com/bitcart/bitcart-fossbilling/blob/master/Bitcart/Bitcart.php
namespace App\Extensions\Gateways\BitCart;
use App\Classes\Extensions\Gateway;
use App\Helpers\ExtensionHelper;
use Illuminate\Support\Facades\Http;
class BitCart extends Gateway
{
/**
* Get the extension metadata
*
* @return array
*/
public function getMetadata()
{
return [
'display_name' => 'BitCart',
'version' => '0.0.1',
'author' => '0ut0f.space',
'website' => 'https://0ut0f.space',
];
}
/**
* Get all the configuration for the extension
*
* @return array
*/
public function getConfig()
{
return [
[
'name' => 'api_endpoint',
'friendlyName' => 'BitCart API endpoint',
'type' => 'text',
'required' => true,
],
[
'name' => 'store_id',
'friendlyName' => 'BitCart store id',
'type' => 'text',
'required' => true,
],
[
'name'=>'admin_url',
'friendlyName' => 'BitCart admin URL',
'type' => 'text',
'required' => true,
],
];
}
/**
* Get the URL to redirect to
*
* @param int $total
* @param array $products
* @param int $invoiceId
*/
public function pay($total, $products, $invoiceId)
{
$payment_url = $this->get_payment_url($invoiceId,$total);
return $payment_url;
}
public function get_payment_url ($invoiceId, $amount) {
$api_domain = ExtensionHelper::getConfig('Bitcart', 'api_endpoint');
$admin_domain = ExtensionHelper::getConfig('Bitcart','admin_url');
$params = array(
'price' => number_format($amount, 2, '.', ''),
'store_id' => ExtensionHelper::getConfig('Bitcart','store_id'),
'currency' => ExtensionHelper::getCurrency(),
'email' => auth()->user()->email,
'redirect_url' => route('clients.invoice.show', $invoiceId),
'order_id' => $invoiceId,
);
$invoice = $this->send_request(sprintf('%s/%s', $api_domain, 'invoices/order_id/' . urlencode($invoiceId)), $params);
return $admin_domain . '/i/' . $invoice->id;
}
public function send_request($url, $data, $post = 1)
{
$post_fields = json_encode($data);
$request_headers = array();
$request_headers[] = 'Content-Type: application/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
if ($post) {
curl_setopt($ch, CURLOPT_POST, $post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
}

View file

@ -1,50 +0,0 @@
<?php
// https://github.com/bitcart/whmcs-plugin/blob/master/modules/gateways/bitcartcheckout.php
// https://github.com/bitcart/bitcart-fossbilling/blob/master/Bitcart/Bitcart.php
use App\Helpers\ExtensionHelper;
public function BitCart_getConfig()
{
return [
[
'name' => 'bitcart_api_endpoint',
'friendlyName' => 'Bitcart domain name',
'type' => 'text',
'description' => 'Your Bitcart instance\'s Merchants API URL.',
'required' => true,
],
[
'name' => 'bitcart_store',
'friendlyName' => 'Bitcart store id',
'type' => 'text',
'description' => 'Store ID of your Bitcart Store.',
'required' => true,
],
[
'name'=>'bitcart_admin_url',
'friendlyName' => 'Admin URL',
'type' => 'text',
'description' => 'Your Bitcart instance\'s Admin Panel URL.',
'required' => true,
],
];
}
public function Bitcart_pay($total, $products, $orderId)
{
}
protected function _generateForm($invoiceID)
{
$htmlOutput = '<button name = "bitcart-payment" class = "btn btn-success btn-sm" onclick = "showModal();return false;">Pay now</button>';
$htmlOutput .= '<script src="' . $this->config['admin_url'] . '/modal/bitcart.js" type="text/javascript"></script>';
$htmlOutput .= '<script type=\'text/javascript\'>';
$htmlOutput .= 'function showModal() {';
$htmlOutput .= 'bitcart.showInvoice(\'' . $invoiceID . '\');';
$htmlOutput .= '}
</script>
</form>';
return $htmlOutput;
}