Skip to content

Commit

Permalink
Merge pull request #33 from farayaz/32-add-isipayment-samin-gateway
Browse files Browse the repository at this point in the history
32 add isipayment samin gateway
  • Loading branch information
mehrdadx10 authored May 14, 2024
2 parents 5914cf3 + 4061309 commit d8c78c3
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 20 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ Larapay is a Laravel package for integrating Iranian payment gateways.

## Gateways | درگاه‌ها

| Class | Name (en) | Name (fa) | Requirements |
| ----------------- | ---------------------------------------------- | ---------------------------- | ---------------------------------------------------- |
| **Azkivam** | [Azkivam](https://azkivam.com/) | ازکی وام | `merchant_id`,`api_key` |
| **BehPardakht** | [Beh Pardakht Mellat](https://behpardakht.com) | به‌پرداخت ملت | `terminalId`, `username`, `password` |
| **Digipay** | [Digipay](https://www.mydigipay.com) | دیجی‌پی | `username`, `password`, `client_id`, `client_secret` |
| **IdPay** | [IdPay](https://idpay.ir) | آیدی‌پی | `apiKey`, `sandbox` |
| **IranKish** | [Iran Kish](https://www.irankish.com) | ایران کیش | `terminalId`, `password`, `acceptorId`, `pubKey` |
| **Keepa** | [Keepa - Kipaa](https://keepa.ir) | کیپا | `token` |
| **MehrIran** | [MehrIran](https://qmb.ir) | بانک مهر ایران | `terminal_id`, `merchant_nid`, `encrypt_key` |
| **Omidpay** | [Omidpay - Sayan Card](https://omidpayment.ir) | امید پی (سایان کارت) | `user_id`, `password` |
| **PardakhtNovin** | [Pardakht Novin](https://pna.co.ir) | پرداخت نوین | `userId`, `password`, `terminalId` |
| **Payir** | [Pay.ir](https://www.pay.ir) | پی.آی‌آر | `api` |
| **PayPing** | [PayPing](https://payping.ir) | پی پینگ | `token` |
| **Polam** | [Polam(Poolam)](https://polam.io) | پولام | `api_key` |
| **Sep** | [Saman Electronic Payment](https://www.sep.ir) | پرداخت الکترونیک سامان (سپ) | `terminalId` |
| **SepehrPay** | [Sepehr Pay](https://www.sepehrpay.com) | پرداخت الکترونیک سپهر (مبنا) | `terminalId` |
| **TejaratBajet** | [Tejarat Bajet](https://mybajet.ir) | بانک تجارت - باجت | `client_id`, `client_secret`, `sandbox` |
| **ZarinPal** | [Zarin Pal](https://www.zarinpal.com) | زرین پال | `merchant_id` |
| **Zibal** | [Zibal](https://zibal.ir) | زیبال | `merchant` |
| ... | | | |
| Class | Name (en) | Name (fa) | Requirements |
| ------------------- | ---------------------------------------------- | ---------------------------- | ----------------------------------------------------- |
| **Azkivam** | [Azkivam](https://azkivam.com/) | ازکی وام | `merchant_id`,`api_key` |
| **BehPardakht** | [Beh Pardakht Mellat](https://behpardakht.com) | به‌پرداخت ملت | `terminalId`, `username`, `password` |
| **Digipay** | [Digipay](https://www.mydigipay.com) | دیجی‌پی | `username`, `password`, `client_id`, `client_secret` |
| **IdPay** | [IdPay](https://idpay.ir) | آیدی‌پی | `apiKey`, `sandbox` |
| **IranKish** | [Iran Kish](https://www.irankish.com) | ایران کیش | `terminalId`, `password`, `acceptorId`, `pubKey` |
| **IsipaymentSamin** | [Isipayment Samin](https://isipayment.ir) | ایزایران ثمین | `merchant_code`, `merchant_password`, `terminal_code` |
| **Keepa** | [Keepa - Kipaa](https://keepa.ir) | کیپا | `token` |
| **MehrIran** | [MehrIran](https://qmb.ir) | بانک مهر ایران | `terminal_id`, `merchant_nid`, `encrypt_key` |
| **Omidpay** | [Omidpay - Sayan Card](https://omidpayment.ir) | امید پی (سایان کارت) | `user_id`, `password` |
| **PardakhtNovin** | [Pardakht Novin](https://pna.co.ir) | پرداخت نوین | `userId`, `password`, `terminalId` |
| **Payir** | [Pay.ir](https://www.pay.ir) | پی.آی‌آر | `api` |
| **PayPing** | [PayPing](https://payping.ir) | پی پینگ | `token` |
| **Polam** | [Polam(Poolam)](https://polam.io) | پولام | `api_key` |
| **Sep** | [Saman Electronic Payment](https://www.sep.ir) | پرداخت الکترونیک سامان (سپ) | `terminalId` |
| **SepehrPay** | [Sepehr Pay](https://www.sepehrpay.com) | پرداخت الکترونیک سپهر (مبنا) | `terminalId` |
| **TejaratBajet** | [Tejarat Bajet](https://mybajet.ir) | بانک تجارت - باجت | `client_id`, `client_secret`, `sandbox` |
| **ZarinPal** | [Zarin Pal](https://www.zarinpal.com) | زرین پال | `merchant_id` |
| **Zibal** | [Zibal](https://zibal.ir) | زیبال | `merchant` |
| ... | | | |

If you don't find the gate you want, let us know or contribute to add it
****
Expand Down
125 changes: 125 additions & 0 deletions src/Gateways/IsipaymentSamin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace Farayaz\Larapay\Gateways;

use Farayaz\Larapay\Exceptions\LarapayException;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Redirect;

final class IsipaymentSamin extends GatewayAbstract
{
private $url = 'https://ipg.isipayment.ir/';

protected $statuses = [];

protected $requirements = ['merchant_code', 'merchant_password', 'terminal_code'];

public function request(
int $id,
int $amount,
string $nationalId,
string $mobile,
string $callbackUrl
): array {
$url = $this->url . 'api/IPGRequestPurchase';
$params = [
'Amount' => $amount,
'PurchaseDate' => Carbon::now()->format('c'),
'MerchantReferenceNumber' => $id,
'ReturnURL' => $callbackUrl,
'Type' => 1,
'NumberOfInstallment' => 1,
];

$result = $this->_request($url, $params);
if ($result['ResponseCode'] != 0) {
throw new LarapayException($result['ResponseInformation']);
}

return [
'token' => $result['Token'],
'fee' => 0,
];
}

public function redirect(int $id, string $token, string $callbackUrl)
{
return Redirect::to($this->url . 'IPG?Token=' . $token);

}

public function verify(
int $id,
int $amount,
string $nationalId,
string $mobile,
string $token,
array $params
): array {
$default = [
'ResponseCode' => null,
'ResponseInformation' => null,
'Token' => null,
'RefNO' => null,
'MerchantReferenceNumber' => null,
];
$params = array_merge($default, $params);

if ($token != $params['Token']) {
throw new LarapayException($this->translateStatus('token-mismatch'));
}

if ($params['ResponseCode'] != 0) {
$message = $this->translateStatus($params['ResponseInformation'] ?? $params['ResponseCode']);
throw new LarapayException($message);
}

$url = $this->url . 'api/ConfirmTransaction';
$data = [
'Token' => $token,
'RefNO' => $params['RefNO'],
'CONFIRM_TRANSACTION_STATUS' => 1,
];
$result = $this->_request($url, $data);
if ($result['ResponseCode'] != 0) {
throw new LarapayException($this->translateStatus($result['ResponseInformation']));
}

return [
'result' => $result['ResponseCode'],
'card' => null,
'reference_id' => $result['RefNO'],
'tracking_code' => $result['RefNO'],
'fee' => 0,
];
}

private function _request(string $url, array $data)
{
$data['MerchantCode'] = $this->config['merchant_code'];
$data['MerchantPassword'] = $this->config['merchant_password'];
$data['TerminalCode'] = $this->config['terminal_code'];

try {
return Http::timeout(10)
->post($url, $data)
->throw()
->json();
} catch (RequestException $e) {
$message = $e->getMessage();

if ($e->response->status() == 400) {
$result = $e->response->json();
$message = Arr::join(Arr::flatten($result['ModelState']), ' ');
}

throw new LarapayException($message);
} catch (ConnectionException $e) {
throw new LarapayException($this->translateStatus('connection-exception'));
}
}
}

0 comments on commit d8c78c3

Please sign in to comment.