Skip to content

Instantly share code, notes, and snippets.

@osbre
Last active January 15, 2019 08:46
Show Gist options
  • Save osbre/c9b18608d97425a4aeae38263d04b16b to your computer and use it in GitHub Desktop.
Save osbre/c9b18608d97425a4aeae38263d04b16b to your computer and use it in GitHub Desktop.
<?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();
}
}
<?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