diff --git a/Application/translations/de/stripe_lang.php b/Application/translations/de/stripe_lang.php index 439ebd2..c6ba11c 100644 --- a/Application/translations/de/stripe_lang.php +++ b/Application/translations/de/stripe_lang.php @@ -28,6 +28,8 @@ 'STRIPE_COUNTRY_ES' => 'Spanien', 'STRIPE_COUNTRY_IT' => 'Italien', 'STRIPE_COUNTRY_NL' => 'Niederlande', + 'STRIPE_CARDS_USED' => 'genutzte Kreditkarten', + 'STRIPE_NEW_CARD' => 'neue Karte', 'STRIPE_ERROR_ORDER_NOT_FOUND' => 'Bestellung konnte nicht gefunden werden', 'STRIPE_ERROR_TRANSACTIONID_NOT_FOUND' => 'Transaktions-Id konnte nicht gefunden werden', diff --git a/Application/translations/en/stripe_lang.php b/Application/translations/en/stripe_lang.php index 46d90f4..ddce621 100644 --- a/Application/translations/en/stripe_lang.php +++ b/Application/translations/en/stripe_lang.php @@ -28,6 +28,8 @@ 'STRIPE_COUNTRY_ES' => 'Spain', 'STRIPE_COUNTRY_IT' => 'Italy', 'STRIPE_COUNTRY_NL' => 'Netherlands', + 'STRIPE_CARDS_USED' => 'credit cards used', + 'STRIPE_NEW_CARD' => 'new credit card', 'STRIPE_ERROR_ORDER_NOT_FOUND' => 'Order not found', 'STRIPE_ERROR_TRANSACTIONID_NOT_FOUND' => 'Transaction id not found', diff --git a/Application/views/frontend/tpl/stripecreditcard.tpl b/Application/views/frontend/tpl/stripecreditcard.tpl index f7daa23..c25817b 100644 --- a/Application/views/frontend/tpl/stripecreditcard.tpl +++ b/Application/views/frontend/tpl/stripecreditcard.tpl @@ -8,39 +8,76 @@ -
- -
- +[{if $oView->stripeGetUsedCards()}] +
+ +
+ + [{foreach from=$oView->stripeGetUsedCards() item=card}] + + [{/foreach}] +
-
+[{/if}] -
- -
-
+
stripeGetUsedCards()}] style="display:none;"[{/if}]> +
+ +
+ +
+
+ +
+ +
+
+
[{oxscript include="https://js.stripe.com/v3/"}] [{capture name="stripeComponentsLoad"}] - var pubKey = '[{$oPaymentModel->getPublishableKey()}]'; - if (pubKey == '') { + [{if false}][{/if}] [{/capture}] [{oxscript add=$smarty.capture.stripeComponentsLoad}] diff --git a/CHANGELOG.md b/CHANGELOG.md index 28b345c..ce4d4eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.3] - 2024-??-?? + +### NEW + +- reuse of credit card data + ## [1.0.2] - 2024-02-09 - Fix onBording in OXID-Enterprise-Environment diff --git a/extend/Application/Controller/PaymentController.php b/extend/Application/Controller/PaymentController.php index cd1683b..1a1f470 100644 --- a/extend/Application/Controller/PaymentController.php +++ b/extend/Application/Controller/PaymentController.php @@ -14,6 +14,8 @@ class PaymentController extends PaymentController_parent { + protected ?array $aStripeUsedCards = null; + /** * Delete sess_challenge from session to trigger the creation of a new order when needed */ @@ -120,13 +122,19 @@ public function validatepayment() $oBasket = Registry::getSession()->getBasket(); $oStripePaymentModel = PaymentHelper::getInstance()->getStripePaymentModel($sPaymentId); - if ($sPaymentId == 'stripecreditcard') { + if ($sPaymentId === 'stripecreditcard') { $sStripeTokenId = $this->getDynValue()['stripe_token_id']; - $oStripeCardRequest = $oStripePaymentModel->getCardRequest(); - $oStripeCardRequest->addRequestParameters($sStripeTokenId, $oBasket->getUser()); - $oCard = $oStripeCardRequest->execute(); - if (!empty($oCard->id)) { - Registry::getSession()->setVariable('stripe_current_payment_method_id', $oCard->id); + $sStripeCard = $this->getDynValue()['stripe_used_card']; + + if(!$sStripeCard || $sStripeCard === 'new') { + $oStripeCardRequest = $oStripePaymentModel->getCardRequest(); + $oStripeCardRequest->addRequestParameters($sStripeTokenId, $oBasket->getUser()); + + $oCard = $oStripeCardRequest->execute(); + $sStripeCard = $oCard->id ?? ''; + } + if ($sStripeCard) { + Registry::getSession()->setVariable('stripe_current_payment_method_id', $sStripeCard); } } else { $oStripePaymentMethodRequest = $oStripePaymentModel->getPaymentMethodRequest(); @@ -152,4 +160,35 @@ public function stripeGetSofortCountries() { return ['AT','BE','DE','ES','IT','NL']; } + + /** + * Template variable getter. Returns possible used cards + * + * @return null|array + */ + public function stripeGetUsedCards(): ?array + { + if (is_null($this->aStripeUsedCards)) { + $this->aStripeUsedCards = []; + $oUser = $this->getUser(); + $sStripeCustomerId = $oUser->getFieldData('stripecustomerid'); + if ($sStripeCustomerId) { + $oPaymentCollection = PaymentHelper::getInstance()->loadStripeApi()->paymentMethods->all([ + 'customer' => $sStripeCustomerId, + 'type' => 'card' + ]); + if (isset($oPaymentCollection->data) && count($oPaymentCollection->data)) { + foreach($oPaymentCollection->data as $oPaymentMethod) { + $this->aStripeUsedCards[] = [ + 'id' => $oPaymentMethod->id, + 'title' => 'XXXX XXXX XXXX ' . $oPaymentMethod->card->last4, + 'expire' => $oPaymentMethod->card->exp_month . '/' . $oPaymentMethod->card->exp_year, + 'holder' => $oPaymentMethod->billing_details->name + ]; + } + } + } + } + return count($this->aStripeUsedCards) ? $this->aStripeUsedCards : null; + } } diff --git a/metadata.php b/metadata.php index 07c2cd0..6af21ab 100644 --- a/metadata.php +++ b/metadata.php @@ -24,7 +24,7 @@ 'en' => 'This module integrates STRIPE as payment provider in your OXID Shop.', ], 'thumbnail' => 'stripe_logo.png', - 'version' => '1.0.2', + 'version' => '1.0.3-rc.1', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com', 'email' => 'info@oxid-esales.com',