Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
omalizadeh committed Nov 12, 2021
2 parents de4af93 + e53eaa7 commit b773dc9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 78 deletions.
2 changes: 1 addition & 1 deletion config/gateway_mellat.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* gateway configurations
*/
'default' => [
'main' => [
'terminal_id' => '',
'username' => '',
'password' => '',
Expand Down
19 changes: 10 additions & 9 deletions config/gateway_novin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
*/
'driver' => Omalizadeh\MultiPayment\Drivers\Novin\Novin::class,

/**
* Headers added to rest api calls
*/
'request_headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],

/**
* Gateway payment page language
* Supported values by gateway: fa, en
Expand All @@ -24,13 +16,22 @@
/**
* gateway configurations
*/
'default' => [
'main' => [
'username' => '',
'password' => '',
'certificate_path' => '', // Certificate file path as string
'certificate_password' => '',
'temp_files_dir' => '', // Temp text files dir path, example: storage_path('novin/')
'callback_url' => 'https://yoursite.com/path/to',
'description' => 'payment using eghtesade novin',
],
'other' => [
'username' => '',
'password' => '',
'certificate_path' => '',
'certificate_password' => '',
'temp_files_dir' => '',
'callback_url' => 'https://yoursite.com/path/to',
'description' => 'payment using eghtesade novin',
]
];
17 changes: 8 additions & 9 deletions config/gateway_pasargad.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
*/
'driver' => Omalizadeh\MultiPayment\Drivers\Pasargad\Pasargad::class,

/**
* Headers added to rest api calls
*/
'request_headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],

/**
* gateway configurations
*/
'default' => [
'main' => [
'merchant_code' => '',
'terminal_code' => '',
'certificate_type' => 'xml_file', // Supported values: xml_file, xml_string
'certificate' => '', // Certificate as a string or certificate.xml file path
'callback_url' => 'https://yoursite.com/path/to',
],
'other' => [
'merchant_code' => '',
'terminal_code' => '',
'certificate_type' => 'xml_file',
'certificate' => '',
'callback_url' => 'https://yoursite.com/path/to',
]
];
19 changes: 2 additions & 17 deletions config/gateway_saman.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@

return [

/**
* Important Note: Saman gateway payment uses RefNum for verification.
* RefNum will be set as invoice transaction_id after successful payment verification
* and it must be saved into database for further use.
*
* Note: Merchant id is the same as Terminal id.
*/

/**
* driver class namespace
*/
'driver' => Omalizadeh\MultiPayment\Drivers\Saman\Saman::class,

/**
* Headers added to rest api calls
*/
'request_headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],

/**
* soap client options
*/
Expand All @@ -32,8 +16,9 @@

/**
* gateway configurations
* merchant_id is the same as terminal_id.
*/
'default' => [
'main' => [
'terminal_id' => '',
'callback_url' => 'https://yoursite.com/path/to',
'callback_method' => 'POST', // Supported values: POST, GET
Expand Down
16 changes: 4 additions & 12 deletions config/gateway_zarinpal.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,19 @@
*/
'driver' => Omalizadeh\MultiPayment\Drivers\Zarinpal\Zarinpal::class,

/**
* rest api call headers
*/
'request_headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],

/**
* gateway configurations
*/
'main' => [
'merchant_id' => '',
'merchant_id' => '',
'callback_url' => 'https://yoursite.com/path/to',
'mode' => 'normal', // Supported values: normal, sandbox, zaringate
'mode' => 'normal', // Supported values: normal, sandbox, zaringate
'description' => 'payment using zarinpal',
],
'other' => [
'merchant_id' => '',
'merchant_id' => '',
'callback_url' => 'https://yoursite.com/path/to',
'mode' => 'sandbox',
'mode' => 'sandbox',
'description' => 'payment using zarinpal',
]
];
8 changes: 0 additions & 8 deletions config/gateway_zibal.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
*/
'driver' => Omalizadeh\MultiPayment\Drivers\Zibal\Zibal::class,

/**
* rest api call headers
*/
'request_headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],

/**
* gateway configurations
*/
Expand Down
8 changes: 4 additions & 4 deletions config/multipayment.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [

/**
* set default gateway
*
* valid pattern --> GATEWAY_NAME.GATEWAY_CONFIG_KEY
* valid GATEWAY_NAME --> zarinpal, saman, mellat, novin, pasargad
*
* valid pattern --> GATEWAY_NAME.GATEWAY_CONFIG_KEY
* valid GATEWAY_NAME --> zarinpal, saman, mellat, novin, pasargad, zibal, payir, idpay
*/
'default_gateway' => env('DEFAULT_GATEWAY', 'zarinpal.main'),

Expand Down
60 changes: 42 additions & 18 deletions src/Drivers/Zarinpal/Zarinpal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ class Zarinpal extends Driver implements UnverifiedPaymentsInterface
public function purchase(): string
{
$response = $this->callApi($this->getPurchaseUrl(), $this->getPurchaseData());

if (isset($response['errors']['code'])) {
$responseCode = (int) $response['errors']['code'];
$message = $this->getStatusMessage($responseCode);

throw new PurchaseFailedException($message, $responseCode);
}

if (empty($response['data']['authority']) || (int) $response['data']['code'] !== $this->getSuccessResponseStatusCode()) {
$message = $this->getStatusMessage($response['data']['code']);
throw new PurchaseFailedException($message, $response['data']['code']);
}

$this->getInvoice()->setTransactionId($response['data']['authority']);

return $response['data']['authority'];
Expand Down Expand Up @@ -52,6 +61,14 @@ public function verify(): Receipt
}

$response = $this->callApi($this->getVerificationUrl(), $this->getVerificationData());

if (isset($response['errors']['code'])) {
$responseCode = (int) $response['errors']['code'];
$message = $this->getStatusMessage($responseCode);

throw new PaymentFailedException($message, $responseCode);
}

$responseCode = (int) $response['data']['code'];

if ($responseCode !== $this->getSuccessResponseStatusCode()) {
Expand All @@ -64,7 +81,7 @@ public function verify(): Receipt

$refId = $response['data']['ref_id'];

return new Receipt($this->getInvoice(), $refId, $refId);
return new Receipt($this->getInvoice(), $refId, $refId, $response['data']['card_pan'] ?? null);
}

public function latestUnverifiedPayments(): array
Expand Down Expand Up @@ -135,21 +152,26 @@ protected function getUnverifiedPaymentsData(): array
protected function getStatusMessage($statusCode): string
{
$messages = [
-1 => "اطلاعات ارسال شده ناقص است.",
-2 => "IP و يا مرچنت كد پذيرنده صحيح نيست",
-3 => "با توجه به محدوديت هاي شاپرك امكان پرداخت با رقم درخواست شده ميسر نمي باشد",
-4 => "سطح تاييد پذيرنده پايين تر از سطح نقره اي است.",
-11 => "درخواست مورد نظر يافت نشد.",
-12 => "امكان ويرايش درخواست ميسر نمي باشد.",
-21 => "هيچ نوع عمليات مالي براي اين تراكنش يافت نشد",
-22 => "تراكنش نا موفق ميباشد",
-33 => "رقم تراكنش با رقم پرداخت شده مطابقت ندارد",
-34 => "سقف تقسيم تراكنش از لحاظ تعداد يا رقم عبور نموده است",
-40 => "اجازه دسترسي به متد مربوطه وجود ندارد.",
-41 => "اطلاعات ارسال شده مربوط به AdditionalData غيرمعتبر ميباشد.",
-42 => "مدت زمان معتبر طول عمر شناسه پرداخت بايد بين 30 دقيه تا 45 روز مي باشد.",
-54 => "درخواست مورد نظر آرشيو شده است",
101 => "عمليات پرداخت موفق بوده و قبلا PaymentVerification تراكنش انجام شده است.",
-9 => "خطای اعتبار سنجی",
-10 => "آی پی یا مرچنت کد صحیح نیست.",
-11 => "مرچنت کد فعال نیست.",
-12 => "تلاش بیش از حد در یک بازه زمانی کوتاه",
-15 => "ترمینال شما به حالت تعلیق درآمده است.",
-16 => "سطح تایید پذیرنده پایین تر از سطح نقره ای است.",
-30 => "اجازه دسترسی به تسویه اشتراکی شناور ندارید.",
-31 => "حساب بانکی تسویه را به پنل اضافه کنید، مقادیر وارد شده برای تسهیم صحیح نیست.",
-32 => "مجموع درصدهای تسهیم از سقف مجاز فراتر رفته است.",
-33 => "درصدهای وارد شده صحیح نیست.",
-34 => "مبلغ از کل تراکنش بالاتر است.",
-35 => "تعداد افراد دریافت کننده تسهیم بیش از حد مجاز است.",
-40 => "خطا در اطلاعات ورودی",
-50 => "مقدار پرداخت شده با مبلغ وریفای متفاوت است.",
-51 => "پرداخت ناموفق",
-52 => "خطای غیرمنتظره، با پشتیبانی در تماس باشید.",
-53 => "اتوریتی برای این مرچنت نیست.",
-54 => "اتوریتی نامعتبر",
100 => "عملیات موفق",
101 => "تراکنش قبلا وریفای شده است.",
];

$unknownError = 'خطای ناشناخته رخ داده است.';
Expand Down Expand Up @@ -232,8 +254,10 @@ private function callApi(string $url, array $data)

$response = Http::withHeaders($headers)->post($url, $data);

if ($response->successful()) {
return $response->json();
$responseArray = $response->json();

if (isset($responseArray['data']['code']) || isset($responseArray['errors']['code'])) {
return $responseArray;
}

throw new HttpRequestFailedException($response->body(), $response->status());
Expand Down

0 comments on commit b773dc9

Please sign in to comment.