update variables and simplify Blockonomics paymentdriver

This commit is contained in:
cnohall 2024-09-03 19:48:59 +09:00
parent eb46de98f1
commit bf9f8eb47e
3 changed files with 8 additions and 50 deletions

View File

@ -73,6 +73,11 @@ class Blockonomics implements MethodInterface
}
try {
// This is where the payment happens
// Will probably have to implement a curl request to the blockonomics API
// to create a new payment request
// Or potentially use an off-site solution
$_invoice = collect($drv->payment_hash->data->invoices)->first();
$cli = $drv->client;
@ -92,63 +97,15 @@ class Blockonomics implements MethodInterface
$urlRedirect = redirect()->route('client.invoice.show', ['invoice' => $_invoice->invoice_id])->getTargetUrl();
$rep = $client->createInvoice(
$drv->store_id,
$request->currency,
$_invoice->invoice_number,
$cli->present()->email(),
$metaData,
$checkoutOptions
);
return redirect($rep->getCheckoutLink());
} catch (\Throwable $e) {
PaymentFailureMailer::dispatch($drv->client, $drv->payment_hash->data, $drv->client->company, $request->amount);
throw new PaymentFailed('Error during Blockonomics payment : ' . $e->getMessage());
}
}
// Not supported yet
public function refund(Payment $payment, $amount)
{
try {
if ($amount == $payment->amount) {
$refundVariant = "Fiat";
$refundPaymentMethod = "BTC";
$refundDescription = "Full refund";
$refundCustomCurrency = null;
$refundCustomAmount = null;
} else {
$refundVariant = "Custom";
$refundPaymentMethod = "";
$refundDescription = "Partial refund";
$refundCustomCurrency = $payment->currency;
$refundCustomAmount = $amount;
}
App::setLocale($payment->company->getLocale());
$email_object = new EmailObject();
$email_object->subject = ctrans('texts.blockonomics_refund_subject');
$email_object->body = ctrans('texts.blockonomics_refund_body') . '<br>' . $refund->getViewLink();
$email_object->text_body = ctrans('texts.blockonomics_refund_body') . '\n' . $refund->getViewLink();
$email_object->company_key = $payment->company->company_key;
$email_object->html_template = 'email.template.generic';
$email_object->to = [new Address($payment->client->present()->email(), $payment->client->present()->name())];
$email_object->email_template_body = 'blockonomics_refund_subject';
$email_object->email_template_subject = 'blockonomics_refund_body';
Email::dispatch($email_object, $payment->company);
$data = [
'transaction_reference' => $refund->getId(),
'transaction_response' => json_encode($refund),
'success' => true,
'description' => "Please follow this link to claim your refund: " . $refund->getViewLink(),
'code' => 202,
];
return $data;
} catch (\Throwable $e) {
throw new PaymentFailed('Error during Blockonomics refund : ' . $e->getMessage());
}
}
}

View File

@ -18,6 +18,7 @@ return new class extends Migration
$fields = new \stdClass;
$fields->apiKey = "";
$fields->callbackUrl = "";
$fields->callbackSecret = md5(uniqid(rand(), true));
$gateway = new Gateway;
$gateway->id = 64;

View File

@ -89,7 +89,7 @@ class PaymentLibrariesSeeder extends Seeder
['id' => 61, 'name' => 'PayPal Platform', 'provider' => 'PayPal_PPCP', 'key' => '80af24a6a691230bbec33e930ab40666', 'fields' => '{"testMode":false}'],
['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":""}'],
['id' => 64, 'name' => 'Blockonomics', 'provider' => 'Blockonomics', 'key' => 'wbhf02us6owgo7p4nfjd0ymssdshks4d', 'fields' => '{"apiKey":"", "callbackUrl":""}'],
['id' => 64, 'name' => 'Blockonomics', 'provider' => 'Blockonomics', 'key' => 'wbhf02us6owgo7p4nfjd0ymssdshks4d', 'fields' => '{"apiKey":"", "callbackUrl":"", "callbackSecret": ""}'],
];
foreach ($gateways as $gateway) {