¨4.0.1¨
This commit is contained in:
@@ -2,18 +2,21 @@
|
||||
|
||||
namespace Modules\Payment\Facades;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\Payment\GatewayManager;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Support\Collection all()
|
||||
* @method static Collection all()
|
||||
* @method static array names()
|
||||
* @method static \Modules\Payment\GatewayInterface get(string $name)
|
||||
* @method static \Modules\Payment\GatewayManager register(string $name, callable|object $driver)
|
||||
* @method static GatewayInterface get(string $name)
|
||||
* @method static GatewayManager register(string $name, callable|object $driver)
|
||||
* @method static int count()
|
||||
* @method static bool isEmpty()
|
||||
* @method static bool isNotEmpty()
|
||||
*
|
||||
* @see \Modules\Payment\GatewayManager
|
||||
* @see GatewayManager
|
||||
*/
|
||||
class Gateway extends Facade
|
||||
{
|
||||
@@ -24,6 +27,6 @@ class Gateway extends Facade
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return \Modules\Payment\GatewayManager::class;
|
||||
return GatewayManager::class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,6 @@ interface GatewayInterface
|
||||
{
|
||||
public function purchase(Order $order, Request $request);
|
||||
|
||||
|
||||
public function complete(Order $order);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,17 @@ use JsonSerializable;
|
||||
|
||||
abstract class GatewayResponse implements JsonSerializable
|
||||
{
|
||||
abstract public function getOrderId();
|
||||
public function __toString()
|
||||
{
|
||||
return json_encode($this->jsonSerialize());
|
||||
}
|
||||
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
@@ -19,13 +29,6 @@ abstract class GatewayResponse implements JsonSerializable
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return json_encode($this->jsonSerialize());
|
||||
}
|
||||
abstract public function getOrderId();
|
||||
}
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use stdClass;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\AuthorizenetResponse;
|
||||
use net\authorize\api\contract\v1 as AnetAPI;
|
||||
use net\authorize\api\constants\ANetEnvironment;
|
||||
use net\authorize\api\controller as AnetController;
|
||||
use stdClass;
|
||||
use Modules\Payment\Responses\AuthorizenetResponse;
|
||||
|
||||
class AuthorizeNet implements GatewayInterface
|
||||
{
|
||||
public const SUPPORTED_CURRENCIES = ['CHF', 'DKK', 'EUR', 'GBP', 'NOK', 'PLN', 'SEK', 'USD', 'AUD', 'NZD', 'CAD'];
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
public const SUPPORTED_CURRENCIES = ['CHF', 'DKK', 'EUR', 'GBP', 'NOK', 'PLN', 'SEK', 'USD', 'AUD', 'NZD', 'CAD'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -24,6 +25,10 @@ class AuthorizeNet implements GatewayInterface
|
||||
$this->description = setting('authorizenet_description');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), self::SUPPORTED_CURRENCIES)) {
|
||||
@@ -35,18 +40,23 @@ class AuthorizeNet implements GatewayInterface
|
||||
return new AuthorizenetResponse($order, $response);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new AuthorizenetResponse($order, request());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getAnAcceptPaymentPage(Order $order)
|
||||
{
|
||||
define('AUTHORIZENET_LOG_FILE', 'phplog');
|
||||
$reference = 'ref' . time();
|
||||
|
||||
$callbackUrl = env('APP_ENV') === 'local' ? 'https://example.com/receipt' : $this->getRedirectUrl($order, $reference);
|
||||
$cancelUrl = env('APP_ENV') === 'local' ? 'https://example.com/cancel' : route('checkout.create');
|
||||
$callbackUrl = config('app.env') === 'local' ? 'https://example.com/receipt' : $this->getRedirectUrl($order, $reference);
|
||||
$cancelUrl = config('app.env') === 'local' ? 'https://example.com/cancel' : route('checkout.create');
|
||||
|
||||
//encode ampersand of the query parameter to make it compatible for api usage
|
||||
$encodedCallbackUrl = str_replace('&', '%26', $callbackUrl);
|
||||
@@ -92,14 +102,14 @@ class AuthorizeNet implements GatewayInterface
|
||||
|
||||
//execute request
|
||||
$controller = new AnetController\GetHostedPaymentPageController($request);
|
||||
$response = $controller->executeWithApiResponse(setting('authorizenet_test_mode') ? \net\authorize\api\constants\ANetEnvironment::SANDBOX : \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
|
||||
$response = $controller->executeWithApiResponse(setting('authorizenet_test_mode') ? ANetEnvironment::SANDBOX : ANetEnvironment::PRODUCTION);
|
||||
|
||||
$extendedResponse = new stdClass();
|
||||
|
||||
if ($response != null && $response->getMessages()->getResultCode() == 'Ok') {
|
||||
$extendedResponse->token = $response->getToken();
|
||||
} else {
|
||||
$errorMessages = $response->getMessages()->getMessage();
|
||||
$errorMessage = $response->getMessages()->getMessage();
|
||||
|
||||
throw new Exception(trans('payment::messages.payment_gateway_error'));
|
||||
}
|
||||
@@ -110,6 +120,7 @@ class AuthorizeNet implements GatewayInterface
|
||||
return $extendedResponse;
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order, $reference)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'authorizenet', 'reference' => $reference]);
|
||||
|
||||
@@ -13,6 +13,7 @@ class BankTransfer implements GatewayInterface
|
||||
public $description;
|
||||
public $instructions;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('bank_transfer_label');
|
||||
@@ -20,11 +21,13 @@ class BankTransfer implements GatewayInterface
|
||||
$this->instructions = setting('bank_transfer_instructions');
|
||||
}
|
||||
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
return new NullResponse($order);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new NullResponse($order);
|
||||
|
||||
@@ -12,17 +12,20 @@ class COD implements GatewayInterface
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('cod_label');
|
||||
$this->description = setting('cod_description');
|
||||
}
|
||||
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
return new NullResponse($order);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new NullResponse($order);
|
||||
|
||||
@@ -13,6 +13,7 @@ class CheckPayment implements GatewayInterface
|
||||
public $description;
|
||||
public $instructions;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('check_payment_label');
|
||||
@@ -20,11 +21,13 @@ class CheckPayment implements GatewayInterface
|
||||
$this->instructions = setting('check_payment_instructions');
|
||||
}
|
||||
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
return new NullResponse($order);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new NullResponse($order);
|
||||
|
||||
@@ -2,21 +2,20 @@
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use stdClass;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\FlutterwaveResponse;
|
||||
use Modules\Payment\Responses\InstamojoResponse;
|
||||
use stdClass;
|
||||
|
||||
class Flutterwave implements GatewayInterface
|
||||
{
|
||||
public const SUPPORTED_CURRENCIES = ['GBP', 'CAD', 'XAF', 'CLP', 'COP', 'EGP', 'EUR', 'GHS', 'GNF', 'KES', 'MWK', 'MAD', 'NGN', 'RWF', 'SLL', 'STD', 'ZAR', 'TZS', 'UGX', 'USD', 'XOF', 'ZMW'];
|
||||
public const PAYMENT_OPTIONS = ['credit', 'ussd', 'nqr', 'barter', 'mobilemoneyzambia', 'mobilemoneyrwanda', 'mobilemoneyuganda', 'mobilemoneyfranco', 'mobilemoneyghana', 'mpesa', 'banktransfer', 'account', 'card'];
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
public const SUPPORTED_CURRENCIES = ['GBP', 'CAD', 'XAF', 'CLP', 'COP', 'EGP', 'EUR', 'GHS', 'GNF', 'KES', 'MWK', 'MAD', 'NGN', 'RWF', 'SLL', 'STD', 'ZAR', 'TZS', 'UGX', 'USD', 'XOF', 'ZMW'];
|
||||
public const PAYMENT_OPTIONS = ['credit', 'ussd', 'nqr', 'barter', 'mobilemoneyzambia', 'mobilemoneyrwanda', 'mobilemoneyuganda', 'mobilemoneyfranco', 'mobilemoneyghana', 'mpesa', 'banktransfer', 'account', 'card'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -24,6 +23,10 @@ class Flutterwave implements GatewayInterface
|
||||
$this->description = setting('flutterwave_description');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), self::SUPPORTED_CURRENCIES)) {
|
||||
@@ -42,13 +45,15 @@ class Flutterwave implements GatewayInterface
|
||||
return new FlutterwaveResponse($order, $response);
|
||||
}
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'flutterwave']);
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new FlutterwaveResponse($order, request()->all());
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'flutterwave']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,19 +13,17 @@ class Instamojo implements GatewayInterface
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('instamojo_label');
|
||||
$this->description = setting('instamojo_description');
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
$endpoint = setting('instamojo_test_mode') ? 'https://test.instamojo.com/api/1.1/' : null;
|
||||
|
||||
return new \Instamojo\Instamojo(setting('instamojo_api_key'), setting('instamojo_auth_token'), $endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (currency() !== 'INR') {
|
||||
@@ -51,13 +49,23 @@ class Instamojo implements GatewayInterface
|
||||
return new InstamojoResponse($order, $response);
|
||||
}
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
|
||||
public function client()
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'instamojo']);
|
||||
$endpoint = setting('instamojo_test_mode') ? 'https://test.instamojo.com/api/1.1/' : null;
|
||||
|
||||
return new \Instamojo\Instamojo(setting('instamojo_api_key'), setting('instamojo_auth_token'), $endpoint);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new InstamojoResponse($order, request()->all());
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'instamojo']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,47 +4,41 @@ namespace Modules\Payment\Gateways;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use MercadoPago\SDK as MercadoPagoSDK;
|
||||
use MercadoPago\Preference as MercadoPagoPreference;
|
||||
use MercadoPago\Item as MercadoPagoItem;
|
||||
use Modules\Order\Entities\Order;
|
||||
use MercadoPago\SDK as MercadoPagoSDK;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use MercadoPago\Item as MercadoPagoItem;
|
||||
use Modules\Payment\Responses\MercadoPagoResponse;
|
||||
use Modules\Support\Money;
|
||||
use MercadoPago\Preference as MercadoPagoPreference;
|
||||
|
||||
class MercadoPago implements GatewayInterface
|
||||
{
|
||||
public const CURRENCIES = ['UYU', 'PEN', 'COP', 'MXN', 'CLP', 'BRL', 'ARS'];
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
public const CURRENCIES = ['UYU', 'PEN', 'COP', 'MXN', 'CLP', 'BRL', 'ARS'];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('mercadopago_label');
|
||||
$this->description = setting('mercadopago_description');
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (setting('mercadopago_enabled')) {
|
||||
MercadoPagoSDK::setAccessToken(setting('mercadopago_access_token'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
$this->init();
|
||||
|
||||
if (!in_array(currency(), $this->getSupportedCurrencies())) {
|
||||
throw new Exception(trans('payment::messages.currency_not_supported'));
|
||||
}
|
||||
|
||||
$preference = new MercadoPagoPreference();
|
||||
|
||||
try {
|
||||
$preference = new MercadoPagoPreference();
|
||||
$preference->items = $this->prepareItems($order);
|
||||
$preference->binary_mode = true;
|
||||
|
||||
@@ -69,15 +63,17 @@ class MercadoPago implements GatewayInterface
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
public function init()
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'mercadopago']);
|
||||
if (setting('mercadopago_enabled')) {
|
||||
MercadoPagoSDK::setAccessToken(setting('mercadopago_access_token'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function getPaymentFailedUrl($order)
|
||||
public function getSupportedCurrencies()
|
||||
{
|
||||
return route('checkout.payment_canceled.store', ['orderId' => $order->id, 'paymentMethod' => 'mercadopago']);
|
||||
return [setting('mercadopago_supported_currency'), 'USD'];
|
||||
}
|
||||
|
||||
|
||||
@@ -155,14 +151,20 @@ class MercadoPago implements GatewayInterface
|
||||
}
|
||||
|
||||
|
||||
public function getSupportedCurrencies()
|
||||
{
|
||||
return [setting('mercadopago_supported_currency'), 'USD'];
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new MercadoPagoResponse($order, request());
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'mercadopago']);
|
||||
}
|
||||
|
||||
|
||||
private function getPaymentFailedUrl($order)
|
||||
{
|
||||
return route('checkout.payment_canceled.store', ['orderId' => $order->id, 'paymentMethod' => 'mercadopago']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Exception;
|
||||
use PayPalHttp\IOException;
|
||||
use Illuminate\Http\Request;
|
||||
use PayPalHttp\HttpException;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use PayPalCheckoutSdk\Core\PayPalHttpClient;
|
||||
@@ -18,27 +20,19 @@ class PayPal implements GatewayInterface
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('paypal_label');
|
||||
$this->description = setting('paypal_description');
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return new PayPalHttpClient($this->environment());
|
||||
}
|
||||
|
||||
private function environment()
|
||||
{
|
||||
if (setting('paypal_test_mode')) {
|
||||
return new SandboxEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
|
||||
}
|
||||
|
||||
return new ProductionEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
|
||||
}
|
||||
|
||||
public function purchase(Order $order, Request $r)
|
||||
/**
|
||||
* @throws HttpException
|
||||
* @throws IOException
|
||||
*/
|
||||
public function purchase(Order $order, Request $req)
|
||||
{
|
||||
try {
|
||||
$request = new OrdersCreateRequest;
|
||||
@@ -51,6 +45,18 @@ class PayPal implements GatewayInterface
|
||||
return new PayPalResponse($order, $this->client()->execute($request));
|
||||
}
|
||||
|
||||
|
||||
public function client()
|
||||
{
|
||||
return new PayPalHttpClient($this->environment());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws HttpException
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function complete(Order $order)
|
||||
{
|
||||
try {
|
||||
@@ -62,6 +68,7 @@ class PayPal implements GatewayInterface
|
||||
return new PayPalResponse($order, $this->client()->execute($request));
|
||||
}
|
||||
|
||||
|
||||
private function buildRequestBody($order)
|
||||
{
|
||||
return [
|
||||
@@ -86,7 +93,7 @@ class PayPal implements GatewayInterface
|
||||
'reference_id' => $order->id,
|
||||
'amount' => [
|
||||
'currency_code' => setting('default_currency'),
|
||||
'value' => (string) $order->total->round()->amount(),
|
||||
'value' => (string)$order->total->round()->amount(),
|
||||
],
|
||||
'shipping' => [
|
||||
'name' => [
|
||||
@@ -110,4 +117,14 @@ class PayPal implements GatewayInterface
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function environment()
|
||||
{
|
||||
if (setting('paypal_test_mode')) {
|
||||
return new SandboxEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
|
||||
}
|
||||
|
||||
return new ProductionEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use stdClass;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\InstamojoResponse;
|
||||
use Modules\Payment\Responses\PaystackResponse;
|
||||
|
||||
class Paystack implements GatewayInterface
|
||||
{
|
||||
const SUPPORTED_CURRENCIES = ['NGN', 'GHS', 'USD', 'ZAR'];
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
const SUPPORTED_CURRENCIES = ['NGN', 'GHS', 'USD', 'ZAR'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -23,17 +21,22 @@ class Paystack implements GatewayInterface
|
||||
$this->description = setting('paystack_description');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), self::SUPPORTED_CURRENCIES)) {
|
||||
throw new Exception(trans('payment::messages.currency_not_supported'));
|
||||
}
|
||||
|
||||
return new PaystackResponse($order, $request);
|
||||
return new PaystackResponse($order);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new PaystackResponse($order, request());
|
||||
return new PaystackResponse($order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,12 @@ class Paytm implements GatewayInterface
|
||||
'services.paytm.industry_type' => 'Retail',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (currency() !== 'INR') {
|
||||
@@ -57,14 +59,14 @@ class Paytm implements GatewayInterface
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'paytm']);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new PaytmResponse($order, request()->all());
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'paytm']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,13 @@ class Razorpay implements GatewayInterface
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('razorpay_label');
|
||||
$this->description = setting('razorpay_description');
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return new Api(setting('razorpay_key_id'), setting('razorpay_key_secret'));
|
||||
}
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
@@ -37,6 +34,13 @@ class Razorpay implements GatewayInterface
|
||||
return new RazorpayResponse($razorpayOrder);
|
||||
}
|
||||
|
||||
|
||||
public function client()
|
||||
{
|
||||
return new Api(setting('razorpay_key_id'), setting('razorpay_key_secret'));
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
$attributes = [
|
||||
|
||||
@@ -6,6 +6,7 @@ use Stripe\PaymentIntent;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Stripe\Exception\ApiErrorException;
|
||||
use Modules\Payment\Responses\StripeResponse;
|
||||
|
||||
class Stripe implements GatewayInterface
|
||||
@@ -13,6 +14,7 @@ class Stripe implements GatewayInterface
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('stripe_label');
|
||||
@@ -21,6 +23,10 @@ class Stripe implements GatewayInterface
|
||||
\Stripe\Stripe::setApiKey(setting('stripe_secret_key'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws ApiErrorException
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
$intent = PaymentIntent::create([
|
||||
@@ -31,6 +37,7 @@ class Stripe implements GatewayInterface
|
||||
return new StripeResponse($order, $intent);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new StripeResponse($order, new PaymentIntent(request('paymentIntent')));
|
||||
|
||||
@@ -2,34 +2,23 @@
|
||||
|
||||
namespace Modules\Payment\Providers;
|
||||
|
||||
use Modules\Payment\Gateways\AuthorizeNet;
|
||||
use Modules\Payment\Gateways\COD;
|
||||
use Modules\Payment\Gateways\Flutterwave;
|
||||
use Modules\Payment\Gateways\Instamojo;
|
||||
use Modules\Payment\Gateways\Paystack;
|
||||
use Modules\Payment\Gateways\Paytm;
|
||||
use Modules\Payment\Facades\Gateway;
|
||||
use Modules\Payment\Gateways\PayPal;
|
||||
use Modules\Payment\Gateways\Paytm;
|
||||
use Modules\Payment\Gateways\Stripe;
|
||||
use Modules\Payment\Gateways\Paystack;
|
||||
use Modules\Payment\Gateways\Razorpay;
|
||||
use Modules\Payment\Gateways\Instamojo;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Payment\Gateways\Flutterwave;
|
||||
use Modules\Payment\Gateways\MercadoPago;
|
||||
use Modules\Payment\Gateways\AuthorizeNet;
|
||||
use Modules\Payment\Gateways\BankTransfer;
|
||||
use Modules\Payment\Gateways\CheckPayment;
|
||||
use Modules\Payment\Gateways\MercadoPago;
|
||||
|
||||
class PaymentServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
@@ -56,13 +45,13 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
|
||||
private function enabled($paymentMethod)
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
if (app('inAdminPanel')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return setting("{$paymentMethod}_enabled");
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +63,16 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
|
||||
private function enabled($paymentMethod)
|
||||
{
|
||||
if (app('inAdminPanel')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return setting("{$paymentMethod}_enabled");
|
||||
}
|
||||
|
||||
|
||||
private function registerStripe()
|
||||
{
|
||||
if ($this->enabled('stripe')) {
|
||||
@@ -106,6 +105,14 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
|
||||
private function registerAuthorizenet()
|
||||
{
|
||||
if ($this->enabled('authorizenet')) {
|
||||
Gateway::register('authorizenet', new AuthorizeNet());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function registerPaystack()
|
||||
{
|
||||
if ($this->enabled('paystack')) {
|
||||
@@ -114,13 +121,6 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
|
||||
private function registerAuthorizenet()
|
||||
{
|
||||
if ($this->enabled('authorizenet')) {
|
||||
Gateway::register('authorizenet', new AuthorizeNet());
|
||||
}
|
||||
}
|
||||
|
||||
private function registerMercadoPago()
|
||||
{
|
||||
if ($this->enabled('mercadopago')) {
|
||||
@@ -128,6 +128,7 @@ class PaymentServiceProvider extends ServiceProvider
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function registerFlutterwave()
|
||||
{
|
||||
if ($this->enabled('flutterwave')) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'only_supports_inr' => 'Only INR currency is supported.',
|
||||
'currency_not_supported' => 'Currency not supported.',
|
||||
'only_supports_inr' => 'Only INR currency is supported',
|
||||
'currency_not_supported' => 'Currency not supported',
|
||||
'payment_gateway_error' => 'Payment gateway error!',
|
||||
'payment_cancelled' => 'Payment cancelled!',
|
||||
];
|
||||
|
||||
@@ -13,7 +13,7 @@ class AuthorizenetResponse extends GatewayResponse implements HasTransactionRefe
|
||||
private $clientResponse;
|
||||
|
||||
|
||||
public function __construct(Order $order,object $clientResponse)
|
||||
public function __construct(Order $order, object $clientResponse)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->clientResponse = $clientResponse;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Modules\Payment\Responses;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\Gateways\MercadoPago;
|
||||
use Modules\Payment\ShouldRedirect;
|
||||
use Modules\Payment\GatewayResponse;
|
||||
use Modules\Payment\HasTransactionReference;
|
||||
@@ -13,29 +12,34 @@ class FlutterwaveResponse extends GatewayResponse implements ShouldRedirect, Has
|
||||
private $order;
|
||||
private $clientResponse;
|
||||
|
||||
|
||||
public function __construct(Order $order, array|object $clientResponse)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->clientResponse = $clientResponse;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
}
|
||||
|
||||
|
||||
public function getRedirectUrl()
|
||||
{
|
||||
return $this->clientResponse['redirect_url'];
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return $this->clientResponse['tx_ref'];
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return (array) $this->clientResponse;
|
||||
return (array)$this->clientResponse;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,26 @@ class InstamojoResponse extends GatewayResponse implements ShouldRedirect, HasTr
|
||||
private $order;
|
||||
private $clientResponse;
|
||||
|
||||
|
||||
public function __construct(Order $order, array $clientResponse)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->clientResponse = $clientResponse;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
}
|
||||
|
||||
|
||||
public function getRedirectUrl()
|
||||
{
|
||||
return $this->clientResponse['redirectUrl'];
|
||||
return $this->clientResponse['longurl'];
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return $this->clientResponse['payment_id'];
|
||||
|
||||
@@ -12,27 +12,32 @@ class MercadoPagoResponse extends GatewayResponse implements ShouldRedirect, Has
|
||||
private $order;
|
||||
private $clientResponse;
|
||||
|
||||
|
||||
public function __construct(Order $order, object $clientResponse)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->clientResponse = $clientResponse;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
}
|
||||
|
||||
|
||||
public function getRedirectUrl()
|
||||
{
|
||||
return $this->clientResponse->back_urls->success;
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return $this->clientResponse->external_reference;
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -9,11 +9,13 @@ class NullResponse extends GatewayResponse
|
||||
{
|
||||
private $order;
|
||||
|
||||
|
||||
public function __construct(Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
|
||||
@@ -12,22 +12,26 @@ class PayPalResponse extends GatewayResponse implements HasTransactionReference
|
||||
private $order;
|
||||
private $httpResponse;
|
||||
|
||||
|
||||
public function __construct(Order $order, HttpResponse $httpResponse)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->httpResponse = $httpResponse;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return $this->httpResponse->result->purchase_units[0]->payments->captures[0]->id;
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return parent::toArray() + ['resourceId' => $this->httpResponse->result->id];
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Modules\Payment\Responses;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\ShouldRedirect;
|
||||
use Modules\Payment\GatewayResponse;
|
||||
use Modules\Payment\HasTransactionReference;
|
||||
|
||||
@@ -11,21 +10,25 @@ class PaystackResponse extends GatewayResponse implements HasTransactionReferenc
|
||||
{
|
||||
private $order;
|
||||
|
||||
|
||||
public function __construct(Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return request('reference');
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -10,21 +10,25 @@ class RazorpayResponse extends GatewayResponse implements HasTransactionReferenc
|
||||
{
|
||||
private $razorpayOrder;
|
||||
|
||||
|
||||
public function __construct(RazorpayOrder $razorpayOrder)
|
||||
{
|
||||
$this->razorpayOrder = $razorpayOrder;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->razorpayOrder->receipt;
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return $this->razorpayOrder->razorpay_payment_id;
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->razorpayOrder->toArray();
|
||||
|
||||
@@ -12,22 +12,26 @@ class StripeResponse extends GatewayResponse implements HasTransactionReference
|
||||
private $order;
|
||||
private $intent;
|
||||
|
||||
|
||||
public function __construct(Order $order, PaymentIntent $intent)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->intent = $intent;
|
||||
}
|
||||
|
||||
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->order->id;
|
||||
}
|
||||
|
||||
|
||||
public function getTransactionReference()
|
||||
{
|
||||
return $this->intent->id;
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return parent::toArray() + ['clientSecret' => $this->intent->client_secret];
|
||||
|
||||
Reference in New Issue
Block a user