From 53f6e0586ce87a9fb48c2d6a3883f7fa699d8d4b Mon Sep 17 00:00:00 2001 From: IceToast Date: Sun, 6 Feb 2022 21:10:05 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20basic=20currency=20?= =?UTF-8?q?support=20for=20invoices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/PaymentController.php | 13 +-- composer.json | 1 + composer.lock | 82 ++++++++++++++++++- 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 68379777..5ed99068 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -31,6 +31,7 @@ use PayPalCheckoutSdk\Orders\OrdersCaptureRequest; use PayPalCheckoutSdk\Orders\OrdersCreateRequest; use PayPalHttp\HttpException; use Stripe\Stripe; +use Symfony\Component\Intl\Currencies; class PaymentController extends Controller @@ -199,7 +200,7 @@ class PaymentController extends Controller //only create invoice if SETTINGS::INVOICE:ENABLED is true if (config('SETTINGS::INVOICE:ENABLED') == 'true') { - $this->createInvoice($user, $payment, 'paid'); + $this->createInvoice($user, $payment, 'paid', $creditProduct->currency_code); } @@ -342,7 +343,7 @@ class PaymentController extends Controller //only create invoice if SETTINGS::INVOICE:ENABLED is true if (config('SETTINGS::INVOICE:ENABLED') == 'true') { - $this->createInvoice($user, $payment, 'paid'); + $this->createInvoice($user, $payment, 'paid', $creditProduct->currency_code); } //redirect back to home @@ -368,7 +369,7 @@ class PaymentController extends Controller //only create invoice if SETTINGS::INVOICE:ENABLED is true if (config('SETTINGS::INVOICE:ENABLED') == 'true') { - $this->createInvoice($user, $payment, 'paid'); + $this->createInvoice($user, $payment, 'paid', $creditProduct->currency_code); } //redirect back to home @@ -428,7 +429,7 @@ class PaymentController extends Controller //only create invoice if SETTINGS::INVOICE:ENABLED is true if (config('SETTINGS::INVOICE:ENABLED') == 'true') { - $this->createInvoice($user, $payment, 'paid'); + $this->createInvoice($user, $payment, 'paid', strtoupper($paymentIntent->currency)); } } } catch (HttpException $ex) { @@ -502,7 +503,7 @@ class PaymentController extends Controller } - protected function createInvoice($user, $payment, $paymentStatus) + protected function createInvoice($user, $payment, $paymentStatus, $currencyCode) { $creditProduct = CreditProduct::where('id', $payment->credit_product_id)->first(); //create invoice @@ -553,6 +554,8 @@ class PaymentController extends Controller ->delimiter("-") ->sequence($newInvoiceID) ->serialNumberFormat(config("SETTINGS::INVOICE:PREFIX") . '{DELIMITER}{SERIES}{SEQUENCE}') + ->currencyCode($currencyCode) + ->currencySymbol(Currencies::getSymbol($currencyCode)) ->notes($notes); if (file_exists($logoPath)) { diff --git a/composer.json b/composer.json index 99c01bed..fb389bd8 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "spatie/laravel-query-builder": "^3.6", "spatie/laravel-validation-rules": "^3.0", "stripe/stripe-php": "^7.107", + "symfony/intl": "^6.0", "yajra/laravel-datatables-oracle": "~9.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 5df1d36a..c26ee5f7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1c860d07605bb48da56d1bb780a82bda", + "content-hash": "d932d84040780b815f087c1d18a1e41d", "packages": [ { "name": "asm89/stack-cors", @@ -5366,6 +5366,86 @@ ], "time": "2022-01-28T11:06:03+00:00" }, + { + "name": "symfony/intl", + "version": "v6.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/intl.git", + "reference": "eeddf6ca4cb4767e554c82182d1ddd5a7ff94f4d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/intl/zipball/eeddf6ca4cb4767e554c82182d1ddd5a7ff94f4d", + "reference": "eeddf6ca4cb4767e554c82182d1ddd5a7ff94f4d", + "shasum": "" + }, + "require": { + "php": ">=8.0.2" + }, + "require-dev": { + "symfony/filesystem": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Intl\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + }, + { + "name": "Eriksen Costa", + "email": "eriksen.costa@infranology.com.br" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library", + "homepage": "https://symfony.com", + "keywords": [ + "i18n", + "icu", + "internationalization", + "intl", + "l10n", + "localization" + ], + "support": { + "source": "https://github.com/symfony/intl/tree/v6.0.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, { "name": "symfony/mime", "version": "v5.4.3",