Last active
January 15, 2019 08:46
-
-
Save osbre/c9b18608d97425a4aeae38263d04b16b to your computer and use it in GitHub Desktop.
PHP class for api https://ssl.easypay.by/merinfo/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Api class for | |
https://ssl.easypay.by/merinfo/ | |
*/ | |
namespace App\Payments; | |
use GuzzleHttp\Exception\GuzzleException; | |
use GuzzleHttp\Client; | |
class EasyPay | |
{ | |
/** | |
* @var string | |
*/ | |
public $merchant; | |
/** | |
* @var string | |
*/ | |
public $webkey; | |
/** | |
* @var integer | |
*/ | |
public $expiried; | |
/** | |
* @var string | |
*/ | |
public $shop; | |
/** | |
* @var string | |
*/ | |
public $order_number; | |
/** | |
* @var float | |
*/ | |
public $sum; | |
/** | |
* @var string | |
*/ | |
public $comment; | |
/** | |
* @var string | |
*/ | |
public $info; | |
/** | |
* @var string | |
*/ | |
public $success_url; | |
/** | |
* @var string | |
*/ | |
public $cancel_url; | |
public function __construct($payment_info = []) | |
{ | |
foreach ($payment_info as $key => $info) { | |
$this->$key = $info; | |
} | |
} | |
public function createGateway() | |
{ | |
$client = new Client(); | |
$request = $client->request('POST', 'https://ssl.easypay.by/weborder/', [ | |
'form_params' => [ | |
'EP_MerNo' => $this->merchant, | |
'EP_OrderNo' => $this->order_number, | |
'EP_Sum' => $this->sum, | |
'EP_Expires' => $this->expiried, | |
'EP_Comment' => $this->comment, | |
'EP_OrderInfo' => $this->info, | |
'EP_Hash' => md5($this->merchant . $this->webkey . $this->order_number . $this->sum), | |
"EP_Success_URL" => $this->success_url ? $this->success_url : url(env('EASYPAY_SUCCESS_URL')), | |
"EP_Cancel_URL" => $this->cancel_url ? $this->cancel_url : url(env('EASYPAY_CANCEL_URL')), | |
"EP_PayType" => 'PT_ERIP', | |
"EP_Encoding" => "utf-8", | |
"EP_Debug" => env('APP_DEBUG') ? 1 : 0 | |
] | |
]); | |
return $request->getBody()->getContents(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\Order; | |
use App\Product; | |
use App\Payments\EasyPay; | |
$product = Product::find(4); | |
$order = Order::find(1); | |
$easypay = new EasyPay([ | |
'merchant' => env('EASYPAY_ERIP_MERCHANT'), | |
'webkey' => env('EASYPAY_ERIP_WEBKEY'), | |
'expiried' => env('EASYPAY_ERIP_EXPIRED'), | |
'shop' => env('EASYPAY_ERIP_SHOP'), | |
'order_number' => $order->id, | |
'sum' => $product->price, | |
'comment' => __('Заказ от магазина ') . env('EASYPAY_ERIP_SHOP'), | |
'info' => __('Заказ №') . $order->id, | |
]); | |
$reference = $easypay->createGateway(); | |
var_dump($reference); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment