first upload all files
This commit is contained in:
117
Modules/Payment/Gateways/AuthorizeNet.php
Normal file
117
Modules/Payment/Gateways/AuthorizeNet.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
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\controller as AnetController;
|
||||
use stdClass;
|
||||
|
||||
class AuthorizeNet implements GatewayInterface
|
||||
{
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
public const SUPPORTED_CURRENCIES = ['CHF', 'DKK', 'EUR', 'GBP', 'NOK', 'PLN', 'SEK', 'USD', 'AUD', 'NZD', 'CAD'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('authorizenet_label');
|
||||
$this->description = setting('authorizenet_description');
|
||||
}
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), self::SUPPORTED_CURRENCIES)) {
|
||||
throw new Exception(trans('payment::messages.currency_not_supported'));
|
||||
}
|
||||
|
||||
$response = $this->getAnAcceptPaymentPage($order);
|
||||
|
||||
return new AuthorizenetResponse($order, $response);
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new AuthorizenetResponse($order, request());
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
//encode ampersand of the query parameter to make it compatible for api usage
|
||||
$encodedCallbackUrl = str_replace('&', '%26', $callbackUrl);
|
||||
|
||||
/* Create a merchantAuthenticationType object with authentication details
|
||||
retrieved from the constants file */
|
||||
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
|
||||
$merchantAuthentication->setName(setting('authorizenet_merchant_login_id'));
|
||||
$merchantAuthentication->setTransactionKey(setting('authorizenet_merchant_transaction_key'));
|
||||
|
||||
//create a transaction
|
||||
$transactionRequestType = new AnetAPI\TransactionRequestType();
|
||||
$transactionRequestType->setTransactionType('authCaptureTransaction');
|
||||
$transactionRequestType->setAmount($order->total->convertToCurrentCurrency()->amount());
|
||||
$transactionRequestType->setCurrencyCode(currency());
|
||||
|
||||
// Set Hosted Form options
|
||||
$hostedPaymentButtonOptions = new AnetAPI\SettingType();
|
||||
$hostedPaymentButtonOptions->setSettingName('hostedPaymentButtonOptions');
|
||||
$hostedPaymentButtonOptions->setSettingValue("{\"text\": \"Pay\"}");
|
||||
|
||||
$hostedPaymentOrderOptions = new AnetAPI\SettingType();
|
||||
$hostedPaymentOrderOptions->setSettingName('hostedPaymentOrderOptions');
|
||||
$hostedPaymentOrderOptions->setSettingValue("{\"show\": false}");
|
||||
|
||||
$hostedPaymentReturnOptions = new AnetAPI\SettingType();
|
||||
$hostedPaymentReturnOptions->setSettingName('hostedPaymentReturnOptions');
|
||||
|
||||
$hostedPaymentReturnOptions->setSettingValue("{\"url\": \"$encodedCallbackUrl\", \"cancelUrl\": \"$cancelUrl\", \"showReceipt\": true}");
|
||||
|
||||
// Build transaction request
|
||||
$request = new AnetAPI\GetHostedPaymentPageRequest();
|
||||
$request->setMerchantAuthentication($merchantAuthentication);
|
||||
|
||||
// Set the transaction's refId
|
||||
$request->setRefId($reference);
|
||||
|
||||
$request->setTransactionRequest($transactionRequestType);
|
||||
|
||||
$request->addToHostedPaymentSettings($hostedPaymentButtonOptions);
|
||||
$request->addToHostedPaymentSettings($hostedPaymentOrderOptions);
|
||||
$request->addToHostedPaymentSettings($hostedPaymentReturnOptions);
|
||||
|
||||
//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);
|
||||
|
||||
$extendedResponse = new stdClass();
|
||||
|
||||
if ($response != null && $response->getMessages()->getResultCode() == 'Ok') {
|
||||
$extendedResponse->token = $response->getToken();
|
||||
} else {
|
||||
$errorMessages = $response->getMessages()->getMessage();
|
||||
|
||||
throw new Exception(trans('payment::messages.payment_gateway_error'));
|
||||
}
|
||||
|
||||
$extendedResponse->data = $response;
|
||||
$extendedResponse->reference = $reference;
|
||||
|
||||
return $extendedResponse;
|
||||
}
|
||||
|
||||
private function getRedirectUrl($order, $reference)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'authorizenet', 'reference' => $reference]);
|
||||
}
|
||||
}
|
||||
32
Modules/Payment/Gateways/BankTransfer.php
Normal file
32
Modules/Payment/Gateways/BankTransfer.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\NullResponse;
|
||||
|
||||
class BankTransfer implements GatewayInterface
|
||||
{
|
||||
public $label;
|
||||
public $description;
|
||||
public $instructions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('bank_transfer_label');
|
||||
$this->description = setting('bank_transfer_description');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
30
Modules/Payment/Gateways/COD.php
Normal file
30
Modules/Payment/Gateways/COD.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\NullResponse;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
32
Modules/Payment/Gateways/CheckPayment.php
Normal file
32
Modules/Payment/Gateways/CheckPayment.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\NullResponse;
|
||||
|
||||
class CheckPayment implements GatewayInterface
|
||||
{
|
||||
public $label;
|
||||
public $description;
|
||||
public $instructions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('check_payment_label');
|
||||
$this->description = setting('check_payment_description');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
54
Modules/Payment/Gateways/Flutterwave.php
Normal file
54
Modules/Payment/Gateways/Flutterwave.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
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 $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()
|
||||
{
|
||||
$this->label = setting('flutterwave_label');
|
||||
$this->description = setting('flutterwave_description');
|
||||
}
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), self::SUPPORTED_CURRENCIES)) {
|
||||
throw new Exception(trans('payment::messages.currency_not_supported'));
|
||||
}
|
||||
|
||||
$response = new stdClass();
|
||||
$response->public_key = setting('flutterwave_public_key');
|
||||
$response->currency = currency();
|
||||
$response->order_id = $order->id;
|
||||
$response->amount = $order->total->convertToCurrentCurrency()->amount();
|
||||
$response->tx_ref = 'ref' . time();
|
||||
$response->payment_options = self::PAYMENT_OPTIONS;
|
||||
$response->redirect_url = $this->getRedirectUrl($order);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
63
Modules/Payment/Gateways/Instamojo.php
Normal file
63
Modules/Payment/Gateways/Instamojo.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\InstamojoResponse;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (currency() !== 'INR') {
|
||||
throw new Exception(trans('payment::messages.only_supports_inr'));
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->client()
|
||||
->paymentRequestCreate([
|
||||
'purpose' => setting('store_name') . " payment for order #{$order->id}",
|
||||
'amount' => $order->total->convertToCurrentCurrency()->round()->amount(),
|
||||
'buyer_name' => $order->customer_full_name,
|
||||
'email' => $order->customer_email,
|
||||
'phone' => $order->customer_phone,
|
||||
'send_sms' => true,
|
||||
'redirect_url' => $this->getRedirectUrl($order),
|
||||
'allow_repeated_payments' => false,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception(trim(trim($e->getMessage()), '"'));
|
||||
}
|
||||
|
||||
return new InstamojoResponse($order, $response);
|
||||
}
|
||||
|
||||
private function getRedirectUrl($order)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'instamojo']);
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new InstamojoResponse($order, request()->all());
|
||||
}
|
||||
}
|
||||
168
Modules/Payment/Gateways/MercadoPago.php
Normal file
168
Modules/Payment/Gateways/MercadoPago.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
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 Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\MercadoPagoResponse;
|
||||
use Modules\Support\Money;
|
||||
|
||||
class MercadoPago implements GatewayInterface
|
||||
{
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), $this->getSupportedCurrencies())) {
|
||||
throw new Exception(trans('payment::messages.currency_not_supported'));
|
||||
}
|
||||
|
||||
try {
|
||||
$preference = new MercadoPagoPreference();
|
||||
$preference->items = $this->prepareItems($order);
|
||||
$preference->binary_mode = true;
|
||||
|
||||
$preference->back_urls = [
|
||||
'success' => $this->getRedirectUrl($order),
|
||||
'failure' => $this->getPaymentFailedUrl($order),
|
||||
];
|
||||
|
||||
$preference->auto_return = 'approved';
|
||||
$preference->external_reference = 'ref' . time();
|
||||
|
||||
$preference->save();
|
||||
} catch (Exception $e) {
|
||||
throw new Exception(trim(trim($e->getMessage()), '"'));
|
||||
} finally {
|
||||
if (!$preference->id) {
|
||||
throw new Exception(trans('payment::messages.payment_gateway_error'));
|
||||
}
|
||||
}
|
||||
|
||||
return new MercadoPagoResponse($order, $preference);
|
||||
}
|
||||
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
|
||||
public function prepareItems($order): array
|
||||
{
|
||||
$items = $this->prepareProductItems($order->products);
|
||||
$taxItem = $this->prepareTaxItem($order);
|
||||
|
||||
if (!empty($taxItem->unit_price)) {
|
||||
$items[] = $this->prepareTaxItem($order);
|
||||
}
|
||||
|
||||
$discountItem = $this->prepareDiscountItem($order);
|
||||
|
||||
if (!empty($discountItem->unit_price)) {
|
||||
$items[] = $this->prepareDiscountItem($order);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
public function prepareProductItems($orderProducts): array
|
||||
{
|
||||
$productItems = [];
|
||||
|
||||
$orderProducts->each(function ($product) use (&$productItems) {
|
||||
$productItem = $this->prepareProductItem($product);
|
||||
if (!empty($productItem->unit_price)) {
|
||||
$productItems[] = $productItem;
|
||||
}
|
||||
});
|
||||
|
||||
return $productItems;
|
||||
}
|
||||
|
||||
|
||||
public function prepareProductItem($orderProduct)
|
||||
{
|
||||
$item = new MercadoPagoItem();
|
||||
$item->title = $orderProduct->product->name;
|
||||
$item->quantity = $orderProduct->qty;
|
||||
$item->currency_id = currency();
|
||||
$item->unit_price = (float)$orderProduct->unit_price->convertToCurrentCurrency()->amount();
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
public function prepareTaxItem($order)
|
||||
{
|
||||
$item = new MercadoPagoItem();
|
||||
$item->title = trans('payment::order.tax');
|
||||
$item->quantity = 1;
|
||||
$item->currency_id = currency();
|
||||
$item->unit_price = (float)$order
|
||||
->totalTax()
|
||||
->convertToCurrentCurrency()
|
||||
->amount();
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
public function prepareDiscountItem($order)
|
||||
{
|
||||
$item = new MercadoPagoItem();
|
||||
$item->title = trans('payment::order.discount');
|
||||
$item->quantity = 1;
|
||||
$item->currency_id = currency();
|
||||
|
||||
$item->unit_price = (float)(-1 * $order->discount->convertToCurrentCurrency()->amount());
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
public function getSupportedCurrencies()
|
||||
{
|
||||
return [setting('mercadopago_supported_currency'), 'USD'];
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new MercadoPagoResponse($order, request());
|
||||
}
|
||||
}
|
||||
113
Modules/Payment/Gateways/PayPal.php
Normal file
113
Modules/Payment/Gateways/PayPal.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use PayPalCheckoutSdk\Core\PayPalHttpClient;
|
||||
use Modules\Payment\Responses\PayPalResponse;
|
||||
use PayPalCheckoutSdk\Core\SandboxEnvironment;
|
||||
use PayPalCheckoutSdk\Core\ProductionEnvironment;
|
||||
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
|
||||
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
|
||||
|
||||
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)
|
||||
{
|
||||
try {
|
||||
$request = new OrdersCreateRequest;
|
||||
$request->prefer('return=representation');
|
||||
$request->body = $this->buildRequestBody($order);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception(json_decode($e->getMessage())->message ?? '');
|
||||
}
|
||||
|
||||
return new PayPalResponse($order, $this->client()->execute($request));
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
try {
|
||||
$request = new OrdersCaptureRequest(request('resourceId'));
|
||||
} catch (Exception $e) {
|
||||
throw new Exception(json_decode($e->getMessage())->message ?? '');
|
||||
}
|
||||
|
||||
return new PayPalResponse($order, $this->client()->execute($request));
|
||||
}
|
||||
|
||||
private function buildRequestBody($order)
|
||||
{
|
||||
return [
|
||||
'intent' => 'CAPTURE',
|
||||
'payer' => [
|
||||
'name' => [
|
||||
'given_name' => $order->customer_first_name,
|
||||
'surname' => $order->customer_last_name,
|
||||
],
|
||||
'email_address' => $order->customer_email,
|
||||
'address' => [
|
||||
'address_line_1' => $order->billing_address_1,
|
||||
'address_line_2' => $order->billing_address_2,
|
||||
'admin_area_2' => $order->billing_city,
|
||||
'admin_area_1' => $order->billing_state,
|
||||
'postal_code' => $order->billing_zip,
|
||||
'country_code' => $order->billing_country,
|
||||
],
|
||||
],
|
||||
'purchase_units' => [
|
||||
[
|
||||
'reference_id' => $order->id,
|
||||
'amount' => [
|
||||
'currency_code' => setting('default_currency'),
|
||||
'value' => (string) $order->total->round()->amount(),
|
||||
],
|
||||
'shipping' => [
|
||||
'name' => [
|
||||
'full_name' => $order->customer_full_name,
|
||||
],
|
||||
'address' => [
|
||||
'address_line_1' => $order->shipping_address_1,
|
||||
'address_line_2' => $order->shipping_address_2,
|
||||
'admin_area_2' => $order->shipping_city,
|
||||
'admin_area_1' => $order->shipping_state,
|
||||
'postal_code' => $order->shipping_zip,
|
||||
'country_code' => $order->shipping_country,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'application_context' => [
|
||||
'brand_name' => setting('store_name'),
|
||||
'shipping_preferences' => 'SET_PROVIDED_ADDRESS',
|
||||
'user_action' => 'PAY_NOW',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
39
Modules/Payment/Gateways/Paystack.php
Normal file
39
Modules/Payment/Gateways/Paystack.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
const SUPPORTED_CURRENCIES = ['NGN', 'GHS', 'USD', 'ZAR'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('paystack_label');
|
||||
$this->description = setting('paystack_description');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new PaystackResponse($order, request());
|
||||
}
|
||||
}
|
||||
70
Modules/Payment/Gateways/Paytm.php
Normal file
70
Modules/Payment/Gateways/Paytm.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\PaytmResponse;
|
||||
use Paytm\JsCheckout\Facades\Paytm as PaytmAlias;
|
||||
|
||||
class Paytm implements GatewayInterface
|
||||
{
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('paytm_label');
|
||||
$this->description = setting('paytm_description');
|
||||
|
||||
config(
|
||||
[
|
||||
'services.paytm.env' => setting('paytm_test_mode') ? 'staging' : 'production',
|
||||
'services.paytm.merchant_id' => setting('paytm_merchant_id'),
|
||||
'services.paytm.merchant_key' => setting('paytm_merchant_key'),
|
||||
'services.paytm.merchant_website' => setting('paytm_test_mode') ? 'WEBSTAGING' : 'DEFAULT',
|
||||
'services.paytm.channel' => 'WEB',
|
||||
'services.paytm.industry_type' => 'Retail',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (currency() !== 'INR') {
|
||||
throw new Exception(trans('payment::messages.only_supports_inr'));
|
||||
}
|
||||
|
||||
$paytm = PaytmAlias::with('receive');
|
||||
$paytm->prepare(
|
||||
[
|
||||
'order' => $order->id,
|
||||
'user' => "$order->customer_first_name $order->customer_last_name",
|
||||
'mobile_number' => $order->customer_phone,
|
||||
'email' => $order->customer_email,
|
||||
'amount' => $order->total->convertToCurrentCurrency()->round()->amount(),
|
||||
'callback_url' => $this->getRedirectUrl($order),
|
||||
]
|
||||
);
|
||||
$response = $paytm->receive();
|
||||
|
||||
return new PaytmResponse($order, $response);
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
55
Modules/Payment/Gateways/Razorpay.php
Normal file
55
Modules/Payment/Gateways/Razorpay.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Razorpay\Api\Api;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Razorpay\Api\Order as RazorpayOrder;
|
||||
use Modules\Payment\Responses\RazorpayResponse;
|
||||
|
||||
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)
|
||||
{
|
||||
$razorpayOrder = $this->client()->order->create([
|
||||
'receipt' => $order->id,
|
||||
'amount' => $order->total->convertToCurrentCurrency()->subunit(),
|
||||
'currency' => currency(),
|
||||
'payment_capture' => true,
|
||||
]);
|
||||
|
||||
return new RazorpayResponse($razorpayOrder);
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
$attributes = [
|
||||
'razorpay_payment_id' => request('razorpay_payment_id'),
|
||||
'razorpay_order_id' => request('razorpay_order_id'),
|
||||
'razorpay_signature' => request('razorpay_signature'),
|
||||
];
|
||||
|
||||
$this->client()->utility->verifyPaymentSignature($attributes);
|
||||
|
||||
$razorpayOrder = new RazorpayOrder;
|
||||
$razorpayOrder->fill($attributes);
|
||||
|
||||
return new RazorpayResponse($razorpayOrder);
|
||||
}
|
||||
}
|
||||
38
Modules/Payment/Gateways/Stripe.php
Normal file
38
Modules/Payment/Gateways/Stripe.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use Stripe\PaymentIntent;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\StripeResponse;
|
||||
|
||||
class Stripe implements GatewayInterface
|
||||
{
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->label = setting('stripe_label');
|
||||
$this->description = setting('stripe_description');
|
||||
|
||||
\Stripe\Stripe::setApiKey(setting('stripe_secret_key'));
|
||||
}
|
||||
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
$intent = PaymentIntent::create([
|
||||
'amount' => $order->total->subunit(),
|
||||
'currency' => setting('default_currency'),
|
||||
]);
|
||||
|
||||
return new StripeResponse($order, $intent);
|
||||
}
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new StripeResponse($order, new PaymentIntent(request('paymentIntent')));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user