¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -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]);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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']);
}
}

View File

@@ -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']);
}
}

View File

@@ -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']);
}
}

View File

@@ -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'));
}
}

View File

@@ -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);
}
}

View File

@@ -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']);
}
}

View File

@@ -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 = [

View File

@@ -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')));