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 27, 2021
2 parents b773dc9 + 056ed67 commit 428ca67
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/IDPay/IDPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function getPurchaseData(): array
'phone' => $mobile,
'mail' => $email,
'desc' => $description,
'callback' => $this->settings['callback_url']
'callback' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url']
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Mellat/Mellat.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function getPurchaseData(): array
'terminalId' => $this->settings['terminal_id'],
'userName' => $this->settings['username'],
'userPassword' => $this->settings['password'],
'callBackUrl' => $this->settings['callback_url'],
'callBackUrl' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'amount' => $this->getInvoice()->getAmount(),
'localDate' => now()->format('Ymd'),
'localTime' => now()->format('Gis'),
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Novin/Novin.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected function getPurchaseData(): array
'TransType' => static::BANK_BUY_TRANSACTION_TYPE,
'ReserveNum' => $this->getInvoice()->getInvoiceId(),
'Amount' => $this->getInvoice()->getAmount(),
'RedirectUrl' => $this->settings['callback_url'],
'RedirectUrl' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'MobileNo' => $phoneNumber,
'Email' => $this->getInvoice()->getEmail(),
'UserId' => $this->getInvoice()->getUserId(),
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Pasargad/Pasargad.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function getPurchaseData(): array
'Action' => static::BANK_BUY_ACTION_CODE,
'MerchantCode' => $this->settings['merchant_code'],
'TerminalCode' => $this->settings['terminal_code'],
'RedirectAddress' => $this->settings['callback_url'],
'RedirectAddress' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'Amount' => $this->getInvoice()->getAmount(),
'Mobile' => $mobile,
'Email' => $this->getInvoice()->getEmail(),
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/PayIr/PayIr.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function getPurchaseData(): array
return [
'api' => $this->settings['api_key'],
'amount' => $this->getInvoice()->getAmount(),
'redirect' => $this->settings['callback_url'],
'redirect' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'mobile' => $mobile,
'factorNumber' => $this->getInvoice()->getInvoiceId(),
'description' => $description,
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Saman/Saman.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function getPurchaseData(): array
'Action' => 'Token',
'TerminalId' => $this->settings['terminal_id'],
'Amount' => $this->getInvoice()->getAmount(),
'RedirectUrl' => $this->settings['callback_url'],
'RedirectUrl' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'CellNumber' => $cellNumber,
'ResNum' => $this->getInvoice()->getInvoiceId(),
];
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Zarinpal/Zarinpal.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function getPurchaseData(): array
return [
'merchant_id' => $this->settings['merchant_id'],
'amount' => $this->getInvoice()->getAmount(),
'callback_url' => $this->settings['callback_url'],
'callback_url' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'description' => $description,
'meta_data' => [
'mobile' => $mobile,
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Zibal/Zibal.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function getPurchaseData(): array
return [
'merchant' => $this->settings['merchant'],
'amount' => $this->getInvoice()->getAmount(),
'callbackUrl' => $this->settings['callback_url'],
'callbackUrl' => $this->getInvoice()->getCallbackUrl() ?: $this->settings['callback_url'],
'description' => $description,
'orderId' => $this->getInvoice()->getInvoiceId(),
'mobile' => $mobile,
Expand Down
10 changes: 5 additions & 5 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Closure;
use Exception;
use ReflectionClass;
use Omalizadeh\MultiPayment\Drivers\Contracts\PurchaseInterface;
use Omalizadeh\MultiPayment\Drivers\Contracts\UnverifiedPaymentsInterface;
use Omalizadeh\MultiPayment\Exceptions\ConfigurationNotFoundException;
use Omalizadeh\MultiPayment\Exceptions\DriverNotFoundException;
use Omalizadeh\MultiPayment\Exceptions\InvalidConfigurationException;
use Omalizadeh\MultiPayment\Drivers\Contracts\PurchaseInterface;
use Omalizadeh\MultiPayment\Drivers\Contracts\UnverifiedPaymentsInterface;
use ReflectionClass;

class Gateway
{
Expand All @@ -22,7 +22,7 @@ class Gateway
* @param Invoice $invoice
* @param Closure|null $callback
* @return RedirectionForm
* @throws Exception
* @throws DriverNotFoundException
*/
public function purchase(Invoice $invoice, ?Closure $callback = null): RedirectionForm
{
Expand Down Expand Up @@ -175,7 +175,7 @@ private function validateDriverInterfaceImplementation(string $interfaceName): v
$reflect = new ReflectionClass($this->getDriver());

if (!$reflect->implementsInterface($interfaceName)) {
throw new Exception("Driver does not implement $interfaceName.");
throw new DriverNotFoundException("Driver does not implement $interfaceName.");
}
}
}
48 changes: 38 additions & 10 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Omalizadeh\MultiPayment;

use Exception;
use Ramsey\Uuid\Uuid;

class Invoice
Expand All @@ -16,6 +17,7 @@ class Invoice
protected ?string $description = null;
protected ?string $phoneNumber = null;
protected ?string $transactionId = null;
protected ?string $callbackUrl = null;

/**
* @param float $amount
Expand All @@ -35,7 +37,7 @@ public function __construct(float $amount, ?string $transactionId = null)
* @param $amount
* @return $this
*/
public function setAmount($amount): Invoice
public function setAmount($amount): self
{
if (config('multipayment.convert_to_rials')) {
$this->amount = $amount * 10;
Expand All @@ -50,57 +52,62 @@ public function setAmount($amount): Invoice
* @param string $id
* @return $this
*/
public function setTransactionId(string $id): Invoice
public function setTransactionId(string $id): self
{
$this->transactionId = $id;

return $this;
}

/**
* @param string $token
* @return $this
*/
public function setToken(string $token): Invoice
public function setToken(string $token): self
{
$this->token = $token;

return $this;
}

/**
* @param string $description
* @return $this
*/
public function setDescription(string $description): Invoice
public function setDescription(string $description): self
{
$this->description = $description;

return $this;
}

/**
* @param string $phone
* @return $this
*/
public function setPhoneNumber(string $phone): Invoice
public function setPhoneNumber(string $phone): self
{
$this->phoneNumber = $phone;

return $this;
}

/**
* @param string $email
* @return $this
*/
public function setEmail(string $email): Invoice
public function setEmail(string $email): self
{
$this->email = $email;

return $this;
}

/**
* @param string $name
* @return $this
*/
public function setUserName(string $name): Invoice
public function setUserName(string $name): self
{
$this->userName = $name;

Expand All @@ -111,22 +118,43 @@ public function setUserName(string $name): Invoice
* @param int $userId
* @return $this
*/
public function setUserId(int $userId): Invoice
public function setUserId(int $userId): self
{
$this->userId = $userId;

return $this;
}

/**
* @param string $invoiceId
* @return $this
*/
public function setInvoiceId(string $invoiceId): Invoice
public function setInvoiceId(string $invoiceId): self
{
$this->invoiceId = $invoiceId;

return $this;
}

/**
* @param string $callbackUrl
* @return $this
*/
public function setCallbackUrl(string $callbackUrl): self
{
$this->callbackUrl = $callbackUrl;

return $this;
}

/**
* @return string|null
*/
public function getCallbackUrl(): ?string
{
return $this->callbackUrl;
}

/**
* @return float
*/
Expand Down Expand Up @@ -209,7 +237,7 @@ public function getUserId(): ?int

/**
* @return string
* @throws \Exception
* @throws Exception
*/
public function getInvoiceId(): string
{
Expand Down
4 changes: 3 additions & 1 deletion src/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Omalizadeh\MultiPayment;

use Exception;

class Receipt
{
protected Invoice $invoice;
Expand Down Expand Up @@ -30,7 +32,7 @@ public function __construct(

/**
* @return string
* @throws \Exception
* @throws Exception
*/
public function getInvoiceId(): string
{
Expand Down
46 changes: 26 additions & 20 deletions src/RedirectionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

namespace Omalizadeh\MultiPayment;

class RedirectionForm
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;

class RedirectionForm implements Arrayable, Responsable
{
protected string $method;
protected array $inputs;
Expand Down Expand Up @@ -45,54 +52,53 @@ public function getInputs(): array
}

/**
* Returns a json response where form fields are wrapped in data key.
* Returns a json response with form info wrapped in data key.
*
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
*/
public function toJsonResponse(): \Illuminate\Http\JsonResponse
public function toJsonResponse(): JsonResponse
{
return response()->json([
'data' => $this->toArray()
]);
}

/**
* Returns redirection form data as array.
*
* @return array
*/
public function toArray(): array
{
return $this->getData();
return [
'action' => $this->getUrl(),
'inputs' => $this->getInputs(),
'method' => $this->getMethod(),
];
}

/**
* Renders a view that redirects to payment gateway automatically.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
* @return Application|Factory|View
*/
public function view()
{
return view('multipayment::gateway_redirect', $this->toArray());
}

/**
* @deprecated
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function render()
public function toResponse($request): JsonResponse
{
return view('multipayment::gateway_redirect', $this->toArray());
return $this->toJsonResponse();
}

/**
* @return array
* @return Application|Factory|View
*
* @deprecated
*/
protected function getData(): array
public function render()
{
return [
'action' => $this->getUrl(),
'inputs' => $this->getInputs(),
'method' => $this->getMethod(),
];
return view('multipayment::gateway_redirect', $this->toArray());
}
}

0 comments on commit 428ca67

Please sign in to comment.