Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Payments;
- use GuzzleHttp\Exception\GuzzleException;
- use GuzzleHttp\Client;
- class EasyPay
- {
- /**
- * @var string
- */
- public $PartnerKey;
- /**
- * @var string
- */
- public $locale;
- /**
- * @var string
- */
- private $requestedSessionId;
- /**
- * @var string
- */
- private $pageId;
- /**
- * @var string
- */
- private $appId;
- /**
- * @var string
- */
- private $appId;
- private $client;
- public function __construct($payment_info = [])
- {
- foreach ($payment_info as $key => $info) {
- $this->$key = $info;
- }
- $this->client = $client = new Client(['base_uri' => 'https://api.easypay.ua/']);
- }
- /**
- * This method should be called when the user first accesses the payment page.
- * If the browser or device changes, the method is called again.
- * @return mixed
- * @throws GuzzleException
- */
- public function createApp()
- {
- $request = $this->client->request('POST', 'api/system/createApp', [
- 'headers' => [
- 'PartnerKey' => $this->PartnerKey,
- 'locale' => $this->locale,
- ]
- ]);
- $response = json_decode($request->getBody()->getContents());
- if (!$response->error) {
- $this->appId = $response->appId;
- $this->requestedSessionId = $response->requestedSessionId;
- $this->pageId = $response->pageId;
- }
- return $response;
- }
- /**
- * Creates a new session instance for the user along with the data storage pages.
- * The lifetime of the session 20 minutes.
- * @return mixed
- * @throws GuzzleException
- */
- public function createSession()
- {
- $request = $this->client->request('POST', 'api/system/createSession', [
- 'headers' => [
- 'PartnerKey' => $this->PartnerKey,
- 'locale' => $this->locale,
- 'AppId' => $this->appId
- ]
- ]);
- $response = json_decode($request->getBody()->getContents());
- if (!$response->error) {
- $this->appId = $response->appId;
- $this->requestedSessionId = $response->requestedSessionId;
- $this->pageId = $response->pageId;
- }
- return $response;
- }
- /**
- * Creates a new instance of the storage page.
- * When a user opens a new page for payment, a new page ID must be created.
- * @return mixed
- * @throws GuzzleException
- */
- public function createPage()
- {
- $request = $this->client->request('POST', 'api/system/createPage', [
- 'headers' => [
- 'PartnerKey' => $this->PartnerKey,
- 'locale' => $this->locale,
- 'AppId' => $this->appId,
- 'requestedSessionId' => $this->requestedSessionId
- ]
- ]);
- $response = json_decode($request->getBody()->getContents());
- if (!$response->error) {
- $this->appId = $response->appId;
- $this->requestedSessionId = $response->requestedSessionId;
- $this->pageId = $response->pageId;
- }
- return $response;
- }
- public function createOrder()
- {
- $request = $this->client->request('POST', 'api/system/createPage', [
- 'headers' => [
- 'PartnerKey' => $this->PartnerKey,
- 'locale' => $this->locale,
- 'AppId' => $this->appId,
- 'requestedSessionId' => $this->requestedSessionId,
- 'PageId' => $this->pageId,
- 'Sign' => base64_encode(hash('sha256', $this->))
- ]
- ]);
- $response = json_decode($request->getBody()->getContents());
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement