Skip to content

Commit

Permalink
add new drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
roshedgostarandev1 committed Sep 8, 2019
1 parent 747bc73 commit 12f7f75
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 33 deletions.
11 changes: 8 additions & 3 deletions README-FA.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@

# درایورهای موجود

- [زرین پال](https://www.zarinpal.com)
- [ایران کیش](http://irankish.com)
- )[بانک سامان](https://www.sep.ir)
- [ایدی پی](https://idpay.ir/)
- [ایران کیش](http://irankish.com/)
- [پی ای ار](https://pay.ir/)
- [پی پینگ](https://www.payping.ir/)
- [پولام](https://poolam.ir/)
- [بانک سامان](https://www.sep.ir)
- [یک پی](https://yekpay.com/)
- [زرین پال](https://www.zarinpal.com/)
- درایورهای دیگر ساخته خواهند شد یا اینکه بسازید و درخواست `merge` بدید.

> در صورتی که درایور مورد نظرتون موجود نیست, میتونید برای درگاه پرداخت موردنظرتون درایور بسازید.
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ This is a Laravel Package for Payment Gateway Integration. This package supports

# List of available drivers

- [zarinpal](https://www.zarinpal.com)
- [irankish](http://irankish.com)
- [idpay](https://idpay.ir/)
- [irankish](http://irankish.com/)
- [payir](https://pay.ir/)
- [payping](https://www.payping.ir/)
- [poolam](https://poolam.ir/)
- [saman](https://www.sep.ir)
- [yekpay](https://yekpay.com/)
- [zarinpal](https://www.zarinpal.com/)
- Others are under way.

> you can create your own custom driver if not exists in the list , read the `Create custom drivers` section.
Expand Down
54 changes: 49 additions & 5 deletions config/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
|
*/
'drivers' => [
'zarinpal' => [// set urls to https://sandbox.zarinpal.com/pg/rest/WebGate/ for using sandbox
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
'idpay' => [
'apiPurchaseUrl' => 'https://api.idpay.ir/v1.1/payment',
'apiPaymentUrl' => 'https://idpay.ir/p/ws-sandbox/',
'apiVerificationUrl' => 'https://api.idpay.ir/v1.1/payment/verify',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
Expand All @@ -39,6 +39,30 @@
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
'payir' => [
'apiPurchaseUrl' => 'https://pay.ir/pg/send/',
'apiPaymentUrl' => 'https://pay.ir/pg/',
'apiVerificationUrl' => 'https://pay.ir/pg/verify/',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
'payping' => [
'apiPurchaseUrl' => 'https://api.payping.ir/v1/pay',
'apiPaymentUrl' => 'https://api.payping.ir/v1/pay/gotoipg',
'apiVerificationUrl' => 'https://api.payping.ir/v1/pay/verify',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
'poolam' => [
'apiPurchaseUrl' => 'https://poolam.ir/invoice/request/',
'apiPaymentUrl' => 'https://poolam.ir/invoice/pay/',
'apiVerificationUrl' => 'https://poolam.ir/invoice/check/',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
'saman' => [
'apiPurchaseUrl' => 'https://sep.shaparak.ir/Payments/InitPayment.asmx?WSDL',
'apiPaymentUrl' => 'https://sep.shaparak.ir/payment.aspx',
Expand All @@ -47,6 +71,21 @@
'callbackUrl' => '',
'description' => 'payment in '.config('app.name'),
],
'yekpay' => [
'apiPurchaseAndVerificationUrl' => 'https://gate.yekpay.com/api/payment/server?wsdl',
'apiPaymentUrl' => 'https://gate.yekpay.com/api/payment/start/',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
'zarinpal' => [// set urls to https://sandbox.zarinpal.com/pg/rest/WebGate/ for using sandbox
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
],

/*
Expand All @@ -62,8 +101,13 @@
|
*/
'map' => [
'zarinpal' => \Shetabit\Payment\Drivers\Zarinpal::class,
'idpay' => \Shetabit\Payment\Drivers\Idpay::class,
'irankish' => \Shetabit\Payment\Drivers\Irankish::class,
'payir' => \Shetabit\Payment\Drivers\Payir::class,
'payping' => \Shetabit\Payment\Drivers\Payping::class,
'poolam' => \Shetabit\Payment\Drivers\Poolam::class,
'saman' => \Shetabit\Payment\Drivers\Saman::class,
'yekpay' => \Shetabit\Payment\Drivers\Yekpay::class,
'zarinpal' => \Shetabit\Payment\Drivers\Zarinpal::class,
]
];
35 changes: 12 additions & 23 deletions src/Drivers/Payir.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ public function purchase()
$response = $this->client->request(
'POST',
$this->settings->apiPurchaseUrl,
["json" => $data]
$data
);
$body = json_decode($response->getBody()->getContents(), true);

if (empty($body['Authority'])) {
$body['Authority'] = null;
} else {
$this->invoice->transactionId($body['Authority']);
if ($body['status'] == 1) {
$this->invoice->transactionId($body['token']);
}

// return the transaction's id
Expand Down Expand Up @@ -121,12 +119,12 @@ public function verify()
$response = $this->client->request(
'POST',
$this->settings->apiVerificationUrl,
['json' => $data]
$data
);
$body = json_decode($response->getBody()->getContents(), true);

if (!isset($body['Status']) || $body['Status'] != 100) {
$this->notVerified($body['Status']);
if ($body['status'] == 0) {
$this->notVerified($body['status']);
}
}

Expand All @@ -139,22 +137,13 @@ public function verify()
private function notVerified($status)
{
$translations = array(
"-1" => "اطلاعات ارسال شده ناقص است.",
"-2" => "IP و يا مرچنت كد پذيرنده صحيح نيست",
"-3" => "با توجه به محدوديت هاي شاپرك امكان پرداخت با رقم درخواست شده ميسر نمي باشد",
"-4" => "سطح تاييد پذيرنده پايين تر از سطح نقره اي است.",
"-11" => "درخواست مورد نظر يافت نشد.",
"-12" => "امكان ويرايش درخواست ميسر نمي باشد.",
"-21" => "هيچ نوع عمليات مالي براي اين تراكنش يافت نشد",
"-22" => "تراكنش نا موفق ميباشد",
"-33" => "رقم تراكنش با رقم پرداخت شده مطابقت ندارد",
"-34" => "سقف تقسيم تراكنش از لحاظ تعداد يا رقم عبور نموده است",
"-40" => "اجازه دسترسي به متد مربوطه وجود ندارد.",
"-41" => "اطلاعات ارسال شده مربوط به AdditionalData غيرمعتبر ميباشد.",
"-42" => "مدت زمان معتبر طول عمر شناسه پرداخت بايد بين 30 دقيه تا 45 روز مي باشد.",
"-54" => "درخواست مورد نظر آرشيو شده است",
"101" => "عمليات پرداخت موفق بوده و قبلا PaymentVerification تراكنش انجام شده است.",
"-1" => "ارسال api الزامی می باشد",
"-2" => "کد تراکنش الزامی است",
"-3" => "درگاه پرداختی با api ارسالی یافت نشد و یا غیر فعال می باشد",
"-4" => "فروشنده غیر فعال می باشد",
"-5" => "تراکنش با خطا مواجه شده است",
);

if (array_key_exists($status, $translations)) {
throw new InvalidPaymentException($translations[$status]);
} else {
Expand Down
164 changes: 164 additions & 0 deletions src/Drivers/Poolam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

namespace Shetabit\Payment\Drivers;

use GuzzleHttp\Client;
use Shetabit\Payment\Abstracts\Driver;
use Shetabit\Payment\Exceptions\InvalidPaymentException;
use Shetabit\Payment\Invoice;

class Poolam extends Driver
{
/**
* Payir Client.
*
* @var object
*/
protected $client;

/**
* Invoice
*
* @var Invoice
*/
protected $invoice;

/**
* Driver settings
*
* @var object
*/
protected $settings;

/**
* Zarinpal constructor.
* Construct the class with the relevant settings.
*
* @param Invoice $invoice
* @param $settings
*/
public function __construct(Invoice $invoice, $settings)
{
$this->invoice($invoice);
$this->settings = (object) $settings;
$this->client = new Client();
}

/**
* Retrieve data from details using its name.
*
* @return string
*/
private function extractDetails($name)
{
return empty($this->invoice->getDetails()[$name]) ? null : $this->invoice->getDetails()[$name];
}

/**
* Purchase Invoice.
*
* @return string
*/
public function purchase()
{
$mobile = $this->extract('mobile');
$description = $this->extract('description');
$factorNumber = $this->extract('factorNumber');

$data = array(
'api' => $this->settings->merchantId,
'amount' => $this->invoice->getAmount(),
'redirect' => $this->settings->callbackUrl,
'mobile' => $mobile,
'description' => $description,
'factorNumber' => $factorNumber,
);

$response = $this->client->request(
'POST',
$this->settings->apiPurchaseUrl,
["json" => $data]
);
$body = json_decode($response->getBody()->getContents(), true);

if (empty($body['Authority'])) {
$body['Authority'] = null;
} else {
$this->invoice->transactionId($body['Authority']);
}

// return the transaction's id
return $this->invoice->getTransactionId();
}

/**
* Pay the Invoice
*
* @return \Illuminate\Http\RedirectResponse|mixed
*/
public function pay()
{
$payUrl = $this->settings->apiPaymentUrl.$this->invoice->getTransactionId();

// redirect using laravel logic
return redirect()->to($payUrl);
}

/**
* Verify payment
*
* @return mixed|void
* @throws InvalidPaymentException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function verify()
{
$data = [
'api' => $this->settings->api,
'token' => $this->invoice->getTransactionId(),
];

$response = $this->client->request(
'POST',
$this->settings->apiVerificationUrl,
['json' => $data]
);
$body = json_decode($response->getBody()->getContents(), true);

if (!isset($body['Status']) || $body['Status'] != 100) {
$this->notVerified($body['Status']);
}
}

/**
* Trigger an exception
*
* @param $status
* @throws InvalidPaymentException
*/
private function notVerified($status)
{
$translations = array(
"-1" => "اطلاعات ارسال شده ناقص است.",
"-2" => "IP و يا مرچنت كد پذيرنده صحيح نيست",
"-3" => "با توجه به محدوديت هاي شاپرك امكان پرداخت با رقم درخواست شده ميسر نمي باشد",
"-4" => "سطح تاييد پذيرنده پايين تر از سطح نقره اي است.",
"-11" => "درخواست مورد نظر يافت نشد.",
"-12" => "امكان ويرايش درخواست ميسر نمي باشد.",
"-21" => "هيچ نوع عمليات مالي براي اين تراكنش يافت نشد",
"-22" => "تراكنش نا موفق ميباشد",
"-33" => "رقم تراكنش با رقم پرداخت شده مطابقت ندارد",
"-34" => "سقف تقسيم تراكنش از لحاظ تعداد يا رقم عبور نموده است",
"-40" => "اجازه دسترسي به متد مربوطه وجود ندارد.",
"-41" => "اطلاعات ارسال شده مربوط به AdditionalData غيرمعتبر ميباشد.",
"-42" => "مدت زمان معتبر طول عمر شناسه پرداخت بايد بين 30 دقيه تا 45 روز مي باشد.",
"-54" => "درخواست مورد نظر آرشيو شده است",
"101" => "عمليات پرداخت موفق بوده و قبلا PaymentVerification تراكنش انجام شده است.",
);
if (array_key_exists($status, $translations)) {
throw new InvalidPaymentException($translations[$status]);
} else {
throw new InvalidPaymentException('خطای ناشناخته ای رخ داده است.');
}
}
}
Loading

0 comments on commit 12f7f75

Please sign in to comment.