Skip to content

Commit 7e56d31

Browse files
committed
add cryptomus integration
1 parent f060e53 commit 7e56d31

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"paypal/paypal-checkout-sdk": "^1.0",
4747
"plisio/plisio-sdk-laravel": "^1.0",
4848
"filament/spatie-laravel-media-library-plugin": "^3.0",
49-
"myfatoorah/library": "^2.2"
49+
"myfatoorah/library": "^2.2",
50+
"cryptomus/api-php-sdk": "^1.0"
5051
}
5152
}

config/filament-payments.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
return [
44
"drivers" => [
5+
\TomatoPHP\FilamentPayments\Services\Drivers\Cryptomus::class,
56
\TomatoPHP\FilamentPayments\Services\Drivers\Fawery::class,
67
\TomatoPHP\FilamentPayments\Services\Drivers\Moyaser::class,
78
\TomatoPHP\FilamentPayments\Services\Drivers\Payfort::class,

src/Services/Drivers/Cryptomus.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace TomatoPHP\FilamentPayments\Services\Drivers;
4+
5+
use Illuminate\Http\Request;
6+
use Cryptomus\Api\Client;
7+
use TomatoPHP\FilamentPayments\Models\Payment;
8+
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentCurrency;
9+
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentGateway;
10+
11+
12+
class Cryptomus extends Driver
13+
{
14+
public static function process(Payment $payment): false|string
15+
{
16+
$gatewayData = $payment->gateway->gateway_parameters;
17+
18+
$cryptomusGateway = Client::payment($gatewayData['payment_key'], $gatewayData['merchant_uuid']);
19+
20+
try {
21+
$param = [
22+
'amount' => strval($payment->amount + $payment->charge),
23+
'currency' => $payment->method_currency,
24+
'order_id' => $payment->trx,
25+
'url_return' => route('payment.cancel', $payment->trx),
26+
'url_success' => route('payments.callback', 'Cryptomus') . "?session=$payment->trx",
27+
'url_callback' => route('payments.callback', 'Cryptomus') . "?session=$payment->trx",
28+
'is_payment_multiple' => true,
29+
'lifetime' => '3600',
30+
'is_refresh' => true,
31+
'course_source' => 'Binance'
32+
];
33+
34+
$response = $cryptomusGateway->create($param);
35+
} catch (\Exception $e) {
36+
$send['error'] = true;
37+
$send['message'] = $e->getMessage();
38+
return json_encode($send);
39+
}
40+
41+
if ($response && $response['status'] == 'check' ) {
42+
$send['redirect'] = $response['url'];
43+
$send['session'] = $response['uuid'];
44+
return json_encode($send);
45+
} else {
46+
$send['error'] = true;
47+
$send['message'] = ['message'];
48+
return json_encode($send);
49+
}
50+
}
51+
52+
public static function verify(Request $request): \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
53+
{
54+
$gatewayData = \TomatoPHP\FilamentPayments\Models\PaymentGateway::where('alias', 'Cryptomus')->orderBy('id', 'desc')->firstOrFail();
55+
$gatewayParameter = $gatewayData->gateway_parameters;
56+
57+
$sessionId = $request->get('session');
58+
59+
$payment = Payment::where('trx', $sessionId)->where('status', 0)->firstOrFail();
60+
61+
$cryptomusGateway = Client::payment($gatewayParameter['payment_key'], $gatewayParameter['merchant_uuid']);
62+
63+
$data = ["order_id" => $sessionId];
64+
65+
$result = $cryptomusGateway->info($data);
66+
67+
if ($result['is_final'] && $result['order_id'] && in_array($result['payment_status'], ['paid', 'paid_over'])) {
68+
self::paymentDataUpdate($payment);
69+
return redirect($payment->success_url);
70+
}
71+
72+
self::paymentDataUpdate($payment, true);
73+
return redirect($payment->failed_url);
74+
}
75+
76+
public function integration(): array
77+
{
78+
return PaymentGateway::make('Cryptomus')
79+
->alias('Cryptomus')
80+
->status(true)
81+
->crypto(true)
82+
->gateway_parameters([
83+
"payment_key" => "",
84+
"merchant_uuid" => ""
85+
])
86+
->supported_currencies([
87+
PaymentCurrency::make('USD')
88+
->symbol('$')
89+
->rate(1)
90+
->minimum_amount(1)
91+
->maximum_amount(1000)
92+
->fixed_charge(0.2)
93+
->percent_charge(2)
94+
->toArray()
95+
])
96+
->toArray();
97+
}
98+
}

0 commit comments

Comments
 (0)