mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #7144 from LarsK1/v5-develop
Added FPX payment integration
This commit is contained in:
commit
6c9cdcea47
@ -114,7 +114,8 @@ class Gateway extends StaticModel
|
||||
GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
|
||||
GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
|
||||
GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
|
||||
GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']]];
|
||||
GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
|
||||
GatewayType::FPX => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']]];
|
||||
case 39:
|
||||
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']]]; //Checkout
|
||||
break;
|
||||
|
@ -38,6 +38,7 @@ class GatewayType extends StaticModel
|
||||
const ACSS = 19;
|
||||
const BECS = 20;
|
||||
const INSTANT_BANK_PAY = 21;
|
||||
const FPX = 22;
|
||||
|
||||
public function gateway()
|
||||
{
|
||||
@ -92,6 +93,8 @@ class GatewayType extends StaticModel
|
||||
return ctrans('texts.payment_type_direct_debit');
|
||||
case self::INSTANT_BANK_PAY:
|
||||
return ctrans('texts.payment_type_instant_bank_pay');
|
||||
case self::FPX:
|
||||
return ctrans('texts.fpx');
|
||||
default:
|
||||
return 'Undefined.';
|
||||
break;
|
||||
|
@ -54,6 +54,7 @@ class PaymentType extends StaticModel
|
||||
const BECS = 43;
|
||||
const ACSS = 44;
|
||||
const INSTANT_BANK_PAY = 45;
|
||||
const FPX = 46;
|
||||
|
||||
public static function parseCardType($cardName)
|
||||
{
|
||||
|
141
app/PaymentDrivers/Stripe/FPX.php
Normal file
141
app/PaymentDrivers/Stripe/FPX.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\PaymentDrivers\Stripe;
|
||||
|
||||
use App\Exceptions\PaymentFailed;
|
||||
use App\Jobs\Mail\PaymentFailureMailer;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\StripePaymentDriver;
|
||||
|
||||
class FPX
|
||||
{
|
||||
/** @var StripePaymentDriver */
|
||||
public StripePaymentDriver $stripe;
|
||||
|
||||
public function __construct(StripePaymentDriver $stripe)
|
||||
{
|
||||
$this->stripe = $stripe;
|
||||
}
|
||||
|
||||
public function authorizeView($data)
|
||||
{
|
||||
return render('gateways.stripe.fpx.authorize', $data);
|
||||
}
|
||||
|
||||
public function paymentView(array $data)
|
||||
{
|
||||
$data['gateway'] = $this->stripe;
|
||||
$data['return_url'] = $this->buildReturnUrl();
|
||||
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
|
||||
$data['client'] = $this->stripe->client;
|
||||
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
|
||||
$data['country'] = $this->stripe->client->country->iso_3166_2;
|
||||
|
||||
$intent = \Stripe\PaymentIntent::create([
|
||||
'amount' => $data['stripe_amount'],
|
||||
'currency' => 'eur',
|
||||
'payment_method_types' => ['fpx'],
|
||||
'customer' => $this->stripe->findOrCreateCustomer(),
|
||||
'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')),
|
||||
|
||||
]);
|
||||
|
||||
$data['pi_client_secret'] = $intent->client_secret;
|
||||
|
||||
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
|
||||
$this->stripe->payment_hash->save();
|
||||
|
||||
return render('gateways.stripe.fpx.pay', $data);
|
||||
}
|
||||
|
||||
private function buildReturnUrl(): string
|
||||
{
|
||||
return route('client.payments.response', [
|
||||
'company_gateway_id' => $this->stripe->company_gateway->id,
|
||||
'payment_hash' => $this->stripe->payment_hash->hash,
|
||||
'payment_method_id' => GatewayType::FPX,
|
||||
]);
|
||||
}
|
||||
|
||||
public function paymentResponse($request)
|
||||
{
|
||||
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all());
|
||||
$this->stripe->payment_hash->save();
|
||||
|
||||
if ($request->redirect_status == 'succeeded') {
|
||||
return $this->processSuccessfulPayment($request->payment_intent);
|
||||
}
|
||||
|
||||
return $this->processUnsuccessfulPayment();
|
||||
}
|
||||
|
||||
public function processSuccessfulPayment(string $payment_intent)
|
||||
{
|
||||
/* @todo: https://github.com/invoiceninja/invoiceninja/pull/3789/files#r436175798 */
|
||||
|
||||
$this->stripe->init();
|
||||
|
||||
$data = [
|
||||
'payment_method' => $payment_intent,
|
||||
'payment_type' => PaymentType::FPX,
|
||||
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
|
||||
'transaction_reference' => $payment_intent,
|
||||
'gateway_type_id' => GatewayType::FPX,
|
||||
];
|
||||
|
||||
$this->stripe->createPayment($data, Payment::STATUS_PENDING);
|
||||
|
||||
SystemLogger::dispatch(
|
||||
['response' => $this->stripe->payment_hash->data, 'data' => $data],
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_SUCCESS,
|
||||
SystemLog::TYPE_STRIPE,
|
||||
$this->stripe->client,
|
||||
$this->stripe->client->company,
|
||||
);
|
||||
|
||||
return redirect()->route('client.payments.index');
|
||||
}
|
||||
|
||||
public function processUnsuccessfulPayment()
|
||||
{
|
||||
$server_response = $this->stripe->payment_hash->data;
|
||||
|
||||
PaymentFailureMailer::dispatch(
|
||||
$this->stripe->client,
|
||||
$server_response,
|
||||
$this->stripe->client->company,
|
||||
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
|
||||
);
|
||||
|
||||
$message = [
|
||||
'server_response' => $server_response,
|
||||
'data' => $this->stripe->payment_hash->data,
|
||||
];
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$message,
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_FAILURE,
|
||||
SystemLog::TYPE_STRIPE,
|
||||
$this->stripe->client,
|
||||
$this->stripe->client->company,
|
||||
);
|
||||
|
||||
throw new PaymentFailed('Failed to process the payment.', 500);
|
||||
}
|
||||
}
|
@ -41,6 +41,7 @@ use App\PaymentDrivers\Stripe\Bancontact;
|
||||
use App\PaymentDrivers\Stripe\BECS;
|
||||
use App\PaymentDrivers\Stripe\ACSS;
|
||||
use App\PaymentDrivers\Stripe\BrowserPay;
|
||||
use App\PaymentDrivers\Stripe\FPX;
|
||||
use App\PaymentDrivers\Stripe\UpdatePaymentMethods;
|
||||
use App\PaymentDrivers\Stripe\Utilities;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -198,6 +199,13 @@ class StripePaymentDriver extends BaseDriver
|
||||
&& in_array($this->client->country->iso_3166_3, ["AUT"]))
|
||||
$types[] = GatewayType::EPS;
|
||||
|
||||
if ($this->client
|
||||
&& $this->client->currency()
|
||||
&& ($this->client->currency()->code == 'MYR')
|
||||
&& isset($this->client->country)
|
||||
&& in_array($this->client->country->iso_3166_3, ["MYS"]))
|
||||
$types[] = GatewayType::FPX;
|
||||
|
||||
if ($this->client
|
||||
&& $this->client->currency()
|
||||
&& ($this->client->currency()->code == 'EUR')
|
||||
@ -266,6 +274,8 @@ class StripePaymentDriver extends BaseDriver
|
||||
return 'gateways.stripe.becs';
|
||||
case GatewayType::ACSS:
|
||||
return 'gateways.stripe.acss';
|
||||
case GatewayType::FPX:
|
||||
return 'gateways.stripe.fpx';
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -540,7 +550,7 @@ class StripePaymentDriver extends BaseDriver
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $request->getCompany()->id)
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->first();
|
||||
->first();
|
||||
}
|
||||
|
||||
if ($payment) {
|
||||
|
2
public/js/clients/payments/stripe-fpx.js
vendored
Normal file
2
public/js/clients/payments/stripe-fpx.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/*! For license information please see stripe-fpx.js.LICENSE.txt */
|
||||
(()=>{var e,t,n,r;function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var i=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",c=null!==(n=null===(r=document.querySelector('meta[name="stripe-account-id"]'))||void 0===r?void 0:r.content)&&void 0!==n?n:"";new function e(t,n){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"setupStripe",(function(){r.stripe=Stripe(r.key),r.stripeConnect&&(r.stripe.stripeAccount=c);var e=r.stripe.elements();return r.fpx=e.create("fpxBank",{style:{base:{padding:"10px 12px",color:"#32325d",fontSize:"16px"}},accountHolderType:"individual"}),r.fpx.mount("#fpx-bank-element"),r})),o(this,"handle",(function(){document.getElementById("pay-now").addEventListener("click",(function(e){document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),r.stripe.confirmFpxPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:{fpx:r.fpx},return_url:document.querySelector('meta[name="return-url"]').content})}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n}(i,c).setupStripe().handle()})();
|
9
public/js/clients/payments/stripe-fpx.js.LICENSE.txt
Normal file
9
public/js/clients/payments/stripe-fpx.js.LICENSE.txt
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
@ -37,6 +37,7 @@
|
||||
"/js/clients/payments/stripe-ideal.js": "/js/clients/payments/stripe-ideal.js?id=73ce56676f9252b0cecf",
|
||||
"/js/clients/payments/stripe-przelewy24.js": "/js/clients/payments/stripe-przelewy24.js?id=f3a14f78bec8209c30ba",
|
||||
"/js/clients/payments/stripe-browserpay.js": "/js/clients/payments/stripe-browserpay.js?id=71e49866d66a6d85b88a",
|
||||
"/js/clients/payments/stripe-fpx.js": "/js/clients/payments/stripe-fpx.js?id=915712157bc0634b9b21",
|
||||
"/css/app.css": "/css/app.css?id=cab8a6526b0f9f71842d",
|
||||
"/css/card-js.min.css": "/css/card-js.min.css?id=62afeb675235451543ad"
|
||||
}
|
||||
|
65
resources/js/clients/payments/stripe-fpx.js
vendored
Normal file
65
resources/js/clients/payments/stripe-fpx.js
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
class ProcessFPXPay {
|
||||
constructor(key, stripeConnect) {
|
||||
this.key = key;
|
||||
this.errors = document.getElementById('errors');
|
||||
this.stripeConnect = stripeConnect;
|
||||
}
|
||||
|
||||
setupStripe = () => {
|
||||
this.stripe = Stripe(this.key);
|
||||
|
||||
if(this.stripeConnect)
|
||||
this.stripe.stripeAccount = stripeConnect;
|
||||
let elements = this.stripe.elements();
|
||||
let style = {
|
||||
base: {
|
||||
// Add your base input styles here. For example:
|
||||
padding: '10px 12px',
|
||||
color: '#32325d',
|
||||
fontSize: '16px',
|
||||
},
|
||||
};
|
||||
this.fpx = elements.create('fpxBank', {style: style, accountHolderType: 'individual',});
|
||||
this.fpx.mount("#fpx-bank-element");
|
||||
return this;
|
||||
};
|
||||
|
||||
handle = () => {
|
||||
document.getElementById('pay-now').addEventListener('click', (e) => {
|
||||
document.getElementById('pay-now').disabled = true;
|
||||
document.querySelector('#pay-now > svg').classList.remove('hidden');
|
||||
document.querySelector('#pay-now > span').classList.add('hidden');
|
||||
|
||||
this.stripe.confirmFpxPayment(
|
||||
document.querySelector('meta[name=pi-client-secret').content,
|
||||
{
|
||||
payment_method: {
|
||||
fpx: this.fpx,
|
||||
},
|
||||
return_url: document.querySelector(
|
||||
'meta[name="return-url"]'
|
||||
).content,
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const publishableKey = document.querySelector(
|
||||
'meta[name="stripe-publishable-key"]'
|
||||
)?.content ?? '';
|
||||
|
||||
const stripeConnect =
|
||||
document.querySelector('meta[name="stripe-account-id"]')?.content ?? '';
|
||||
|
||||
new ProcessFPXPay(publishableKey, stripeConnect).setupStripe().handle();
|
@ -4543,6 +4543,7 @@ $LANG = array(
|
||||
'activity_122' => ':user archived recurring expense :recurring_expense',
|
||||
'activity_123' => ':user deleted recurring expense :recurring_expense',
|
||||
'activity_124' => ':user restored recurring expense :recurring_expense',
|
||||
'fpx' => "FPX",
|
||||
|
||||
);
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.bank_account'), 'card_title' => ctrans('texts.bank_account')])
|
||||
|
||||
@section('gateway_content')
|
||||
@component('portal.ninja2020.components.general.card-element-single', ['title' => ctrans('texts.bank_account'), 'show_title' => false])
|
||||
{{ __('texts.sofort_authorize_label') }}
|
||||
@endcomponent
|
||||
@endsection
|
@ -0,0 +1,8 @@
|
||||
<div id="stripe--payment-container">
|
||||
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.name')])
|
||||
<label for="fpx-bank-element"></label>
|
||||
<div class="border p-4 rounded">
|
||||
<div id="fpx-bank-element"></div>
|
||||
</div>
|
||||
@endcomponent
|
||||
</div>
|
@ -0,0 +1,28 @@
|
||||
@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'FPX', 'card_title' => 'FPX'])
|
||||
|
||||
@section('gateway_head')
|
||||
<meta name="stripe-publishable-key" content="{{ $gateway->getPublishableKey() }}">
|
||||
<meta name="stripe-account-id" content="{{ $gateway->company_gateway->getConfigField('account_id') }}">
|
||||
<meta name="return-url" content="{{ $return_url }}">
|
||||
<meta name="amount" content="{{ $stripe_amount }}">
|
||||
<meta name="country" content="{{ $country }}">
|
||||
<meta name="customer" content="{{ $customer }}">
|
||||
<meta name="pi-client-secret" content="{{ $pi_client_secret }}">
|
||||
@endsection
|
||||
|
||||
@section('gateway_content')
|
||||
<div class="alert alert-failure mb-4" hidden id="errors"></div>
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.payment_details')
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')])
|
||||
{{ ctrans('texts.fpx') }} ({{ ctrans('texts.bank_transfer') }})
|
||||
@endcomponent
|
||||
@include('portal.ninja2020.gateways.stripe.fpx.fpx')
|
||||
@include('portal.ninja2020.gateways.includes.pay_now')
|
||||
@endsection
|
||||
|
||||
@push('footer')
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script src="{{ asset('js/clients/payments/stripe-fpx.js') }}"></script>
|
||||
@endpush
|
2
webpack.mix.js
vendored
2
webpack.mix.js
vendored
@ -150,6 +150,8 @@ mix.js("resources/js/app.js", "public/js")
|
||||
"resources/js/clients/payments/stripe-browserpay.js",
|
||||
"public/js/clients/payments/stripe-browserpay.js"
|
||||
)
|
||||
.js("resources/js/clients/payments/stripe-fpx.js",
|
||||
"public/js/clients/payments/stripe-fpx.js")
|
||||
|
||||
mix.copyDirectory('node_modules/card-js/card-js.min.css', 'public/css/card-js.min.css');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user