Skip to content

Commit

Permalink
add binance,payeer,nowpayments,perfectmoney
Browse files Browse the repository at this point in the history
  • Loading branch information
NafezlyDotCom committed Jul 9, 2023
1 parent 1c6ab2e commit 3eca020
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 14 deletions.
20 changes: 20 additions & 0 deletions config/nafezly-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@
'BINANCE_SECRET'=>env('BINANCE_SECRET'),



#NowPayments
'NOWPAYMENTS_API_KEY'=>env('NOWPAYMENTS_API_KEY'),


#Payeer
'PAYEER_MERCHANT_ID'=>env('PAYEER_MERCHANT_ID'),
'PAYEER_API_KEY'=>env('PAYEER_API_KEY'),
'PAYEER_ADDITIONAL_API_KEY'=>env('PAYEER_ADDITIONAL_API_KEY'),


#Perfectmoney
/*
*please
*1- create POST route /payments/verify/perfectmoney
*2- put it into app/Http/Middleware/VerifyCsrfToken.php middleware inside except array
*/
'PERFECT_MONEY_ID'=>env('PERFECT_MONEY_ID','UXXXXXXX'),
'PERFECT_MONEY_PASSPHRASE'=>env('PERFECT_MONEY_PASSPHRASE'),

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

Expand Down
43 changes: 29 additions & 14 deletions src/Classes/BinancePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use Nafezly\Payments\Interfaces\PaymentInterface;
use Nafezly\Payments\Classes\BaseController;
use Illuminate\Support\Str;


class BinancePayment extends BaseController implements PaymentInterface
{
Expand Down Expand Up @@ -102,21 +104,34 @@ public function pay($amount = null, $user_id = null, $user_first_name = null, $u
*/
public function verify(Request $request)
{
if ($request['status']=="SUCCESS") {
return [
'success' => true,
'payment_id'=>"",
'message' => __('nafezly::messages.PAYMENT_DONE'),
'process_data' => $request->all()
];
} else {
return [
'success' => false,
'payment_id'=>"",
'message' => __('nafezly::messages.PAYMENT_FAILED'),
'process_data' => $request->all()
];

$payload = $request->getContent();
$signature = $request->header('X-MAC-Signature');
$secretKey = $this->binance_secret; // Replace with your actual Binance secret key

$computedSignature = hash_hmac('sha256', $payload, $secretKey);

if ($signature === $computedSignature) {
// Signature verification successful
$data = json_decode($payload, true);
$paymentId = $data['paymentId']; // Retrieve the payment ID
$paymentStatus = $data['paymentStatus']; // Retrieve the payment status

if ($paymentStatus === 'completed') {
return [
'success' => true,
'payment_id'=>"",
'message' => __('nafezly::messages.PAYMENT_DONE'),
'process_data' => $request->all()
];
}
}
return [
'success' => false,
'payment_id'=>"",
'message' => __('nafezly::messages.PAYMENT_FAILED'),
'process_data' => $request->all()
];
}

}
107 changes: 107 additions & 0 deletions src/Classes/NowPaymentsPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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 NowPaymentsPayment 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');

if($this->get_minimum_amount($this->currency,'usd')>$this->amount){
return [
'payment_id'=>"",
'html'=>"",
'redirect_url'=>"",
'error'=>"AMOUNT_MINIMAL_ERROR"
];
}
$order_id = uniqid().rand(10000,99999);
$response = Http::withHeaders([
'x-api-key' => $this->nowpayments_api_key,
])->post('https://api.nowpayments.io/v1/payment',[
"price_amount"=> $this->amount,
"price_currency"=> "usd",
"pay_currency"=> $this->currency,
"ipn_callback_url"=> route($this->verify_route_name,['payment'=>"nowpayments"]),
"order_id"=> $order_id,
"order_description"=> "Credit"
])->json();
if(isset($response['payment_status']) && $response['payment_status'] == "waiting")
return [
'payment_id'=>$response['payment_id'],
'html'=>$response,
'redirect_url'=>$response['pay_address'],
'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
])->post('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' => $request->all()
];
} else {
return [
'success' => false,
'payment_id'=>$request->payment_id,
'message' => __('nafezly::messages.PAYMENT_FAILED'),
'process_data' => $request->all()
];
}
}
public function get_minimum_amount($from,$to,$fiat_equivalent="usd"){
$response = \Http::withHeaders(['x-api-key'=>$this->nowpayments_api_key])->get('https://api.nowpayments.io/v1/min-amount?currency_from='.$from.'&currency_to='.$to.'&fiat_equivalent='.$fiat_equivalent)->json();
return $response['fiat_equivalent'];

}

}
139 changes: 139 additions & 0 deletions src/Classes/PayeerPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?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 PayeerPayment extends BaseController implements PaymentInterface
{


public $payeer_api_key;
public $payeer_additional_api_key;
public $payeer_merchant_id;
public $verify_route_name;

public function __construct()
{
$this->payeer_api_key = config('nafezly-payments.PAYEER_API_KEY');
$this->payeer_additional_api_key = config('nafezly-payments.PAYEER_ADDITIONAL_API_KEY');
$this->payeer_merchant_id = config('nafezly-payments.PAYEER_MERCHANT_ID');
$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'];
$this->checkRequiredFields($required_fields, 'PAYEER');

$m_shop = $this->payeer_merchant_id;
$m_orderid = uniqid().rand(10000,99999);
$m_amount = number_format($this->amount, 2, '.', '');
$m_curr = 'USD';
$m_desc = base64_encode('credit');

$m_key = $this->payeer_api_key;
$arHash = [
$m_shop,
$m_orderid,
$m_amount,
$m_curr,
$m_desc
];
$arParams = [
'success_url' => route($this->verify_route_name,['payment'=>'payeer']),
'fail_url' => route($this->verify_route_name,['payment'=>'payeer']),
'status_url' => route($this->verify_route_name,['payment'=>'payeer']),
];
$key = md5($this->payeer_additional_api_key.$m_orderid);
$m_params = urlencode(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key, json_encode($arParams), MCRYPT_MODE_ECB)));
$arHash[] = $m_params;
$arHash[] = $m_key;
$sign = strtoupper(hash('sha256', implode(':', $arHash)));
$arGetParams = [
'm_shop' => $m_shop,
'm_orderid' => $m_orderid,
'm_amount' => $m_amount,
'm_curr' => $m_curr,
'm_desc' => $m_desc,
'm_sign' => $sign,
'm_params' => $m_params,
];
$url = 'https://payeer.com/merchant/?'.http_build_query($arGetParams);
if($url!=null)
return [
'payment_id'=>$m_orderid,
'html'=>"",
'redirect_url'=>$url
];
return [
'payment_id'=>$m_orderid,
'html'=>"",
'redirect_url'=>""
];
}

/**
* @param Request $request
* @return array|void
*/
public function verify(Request $request)
{
//if (!in_array($_SERVER['REMOTE_ADDR'], array('185.71.65.92', '185.71.65.189','149.202.17.210'))) return;
if(isset($request['m_operation_id']) && isset($request['m_sign'])){
$m_key = $this->payeer_api_key;
$arHash = [
$request['m_operation_id'],
$request['m_operation_ps'],
$request['m_operation_date'],
$request['m_operation_pay_date'],
$request['m_shop'],
$request['m_orderid'],
$request['m_amount'],
$request['m_curr'],
$request['m_desc'],
$request['m_status']
];

if (isset($request['m_params']))
$arHash[] = $request['m_params'];

$arHash[] = $m_key;
$sign_hash = strtoupper(hash('sha256', implode(':', $arHash)));
if ($request['m_sign'] == $sign_hash && $request['m_status'] == 'success'){
return [
'success' => true,
'payment_id'=>$request['m_orderid'],
'message' => __('nafezly::messages.PAYMENT_DONE'),
'process_data' => $request->all()
];
}
}
return [
'success' => false,
'payment_id'=>$request['m_orderid'],
'message' => __('nafezly::messages.PAYMENT_FAILED'),
'process_data' => $request->all()
];


}

}
Loading

0 comments on commit 3eca020

Please sign in to comment.