Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NafezlyDotCom committed Aug 31, 2023
1 parent bd5e4be commit 9c7aa30
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ return [
'CLICKPAY_SERVER_KEY'=>env('CLICKPAY_SERVER_KEY'),
'CLICKPAY_PROFILE_ID'=>env('CLICKPAY_PROFILE_ID')

'VERIFY_ROUTE_NAME' => "payment-verify",
'VERIFY_ROUTE_NAME' => "verify-payment",
'APP_NAME'=>env('APP_NAME'),
//and more config for another payment gateways
];
```

## Web.php MUST Have Route with name “payment-verify”
## Web.php MUST Have Route with name “verify-payment

```php
Route::get('/payments/verify/{payment?}',[FrontController::class,'payment_verify'])->name('payment-verify');
Route::get('/payments/verify/{payment?}',[FrontController::class,'payment_verify'])->name('verify-payment');
```

## How To Use
Expand Down
2 changes: 1 addition & 1 deletion config/nafezly-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
'PERFECT_MONEY_ID'=>env('PERFECT_MONEY_ID','UXXXXXXX'),
'PERFECT_MONEY_PASSPHRASE'=>env('PERFECT_MONEY_PASSPHRASE'),

'VERIFY_ROUTE_NAME' => "payment-verify",
'VERIFY_ROUTE_NAME' => "verify-payment",
'APP_NAME'=>env('APP_NAME'),


Expand Down
96 changes: 96 additions & 0 deletions src/Classes/NowPaymentsInvoicePayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Nafezly\Payments\Classes;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

use Nafezly\Payments\Interfaces\PaymentInterface;
use Nafezly\Payments\Classes\BaseController;

class NowPaymentsInvoicePayment extends BaseController implements PaymentInterface
{
public $nowpayments_api_key;
public $verify_route_name;

public function __construct()
{
$this->nowpayments_api_key = config('nafezly-payments.NOWPAYMENTS_API_KEY');
$this->verify_route_name = config('nafezly-payments.VERIFY_ROUTE_NAME');
}


/**
* @param $amount
* @param null $user_id
* @param null $user_first_name
* @param null $user_last_name
* @param null $user_email
* @param null $user_phone
* @param null $source
* @return string[]
* @throws MissingPaymentInfoException
*/
public function pay($amount = null, $user_id = null, $user_first_name = null, $user_last_name = null, $user_email = null, $user_phone = null, $source = null): array
{
$this->setPassedVariablesToGlobal($amount,$user_id,$user_first_name,$user_last_name,$user_email,$user_phone,$source);
$required_fields = ['amount','currency'];
$this->checkRequiredFields($required_fields, 'NOWPAYMENTS');

$order_id = uniqid().rand(10000,99999);
$response = Http::withHeaders([
'x-api-key' => $this->nowpayments_api_key,
"Content-Type"=>"application/json"
])->post('https://api.nowpayments.io/v1/invoice',[
"price_amount"=> $this->amount,
"price_currency"=> $this->currency,
"order_id"=> $order_id,
"order_description"=> "Credit",
"ipn_callback_url"=> route($this->verify_route_name,['payment'=>"nowpaymentsinvoice"]),
"success_url"=>route($this->verify_route_name,['payment'=>"nowpaymentsinvoice"]),
"cancel_url"=>route($this->verify_route_name,['payment'=>"nowpaymentsinvoice"]),
])->json();
if(isset($response['id']))
return [
'payment_id'=>$response['id'],
'html'=>$response,
'redirect_url'=>$response['invoice_url'],
'error'=>""
];
return [
'payment_id'=>"",
'html'=>"",
'redirect_url'=>"",
'error'=>$response['code']
];
}

/**
* @param Request $request
* @return array|void
*/
public function verify(Request $request)
{

$response = \Http::withHeaders([
'x-api-key'=>$this->nowpayments_api_key
])->get('https://api.nowpayments.io/v1/payment/'.$request['payment_id'])->json();

if (isset($response['payment_status']) && $response['payment_status'] == "finished") {
return [
'success' => true,
'payment_id'=>$request->payment_id,
'message' => __('nafezly::messages.PAYMENT_DONE'),
'process_data' => $response
];
} else {
return [
'success' => false,
'payment_id'=>$request->payment_id,
'message' => __('nafezly::messages.PAYMENT_FAILED'),
'process_data' => $response
];
}
}

}

0 comments on commit 9c7aa30

Please sign in to comment.