-
+
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',