Skip to content

Commit 0c706ce

Browse files
Merge pull request #1241 from buckaroo-it/develop
Update, Test & Release (1.52.1)
2 parents 5066eb4 + 772ea3e commit 0c706ce

File tree

23 files changed

+747
-293
lines changed

23 files changed

+747
-293
lines changed

Model/ConfigProvider/Method/Applepay.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class Applepay extends AbstractConfigProvider
4141
const XPATH_APPLEPAY_AVAILABLE_IN_BACKEND = 'payment/buckaroo_magento2_applepay/available_in_backend';
4242
const XPATH_APPLEPAY_AVAILABLE_BUTTONS = 'payment/buckaroo_magento2_applepay/available_buttons';
4343
const XPATH_APPLEPAY_BUTTON_STYLE = 'payment/buckaroo_magento2_applepay/button_style';
44-
const XPATH_APPLEPAY_DONT_ASK_BILLING_INFO_IN_CHECKOUT = 'payment/'.
45-
'buckaroo_magento2_applepay/dont_ask_billing_info_in_checkout';
44+
const XPATH_APPLEPAY_INTEGRATION_MODE = 'payment/buckaroo_magento2_applepay/integration_mode';
45+
46+
const XPATH_APPLEPAY_DONT_ASK_BILLING_INFO_IN_CHECKOUT = 'payment/buckaroo_magento2_applepay/dont_ask_billing_info_in_checkout';
4647

4748
const XPATH_ALLOWED_CURRENCIES = 'payment/buckaroo_magento2_applepay/allowed_currencies';
4849
const XPATH_ALLOW_SPECIFIC = 'payment/buckaroo_magento2_applepay/allowspecific';
@@ -125,7 +126,8 @@ public function getConfig()
125126
'dontAskBillingInfoInCheckout' => (int) $this->scopeConfig->getValue(
126127
static::XPATH_APPLEPAY_DONT_ASK_BILLING_INFO_IN_CHECKOUT,
127128
ScopeInterface::SCOPE_STORE
128-
)
129+
),
130+
'integrationMode' => $this->getIntegrationMode($store),
129131
],
130132
],
131133
],
@@ -176,4 +178,15 @@ public function isApplePayEnabled($store = null)
176178
{
177179
return $this->getConfigFromXpath(self::XPATH_APPLEPAY_ACTIVE, $store);
178180
}
181+
182+
public function getIntegrationMode($store = null): bool
183+
{
184+
$integrationMode = $this->getConfigFromXpath(self::XPATH_APPLEPAY_INTEGRATION_MODE, $store);
185+
186+
if ($integrationMode == 1) {
187+
return true;
188+
}
189+
190+
return false;
191+
}
179192
}

Model/Method/Applepay.php

Lines changed: 152 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
namespace Buckaroo\Magento2\Model\Method;
2121

22+
use Buckaroo\Magento2\Exception;
23+
2224
class Applepay extends AbstractMethod
2325
{
2426
/** Payment Code */
@@ -42,10 +44,34 @@ public function assignData(\Magento\Framework\DataObject $data)
4244
parent::assignData($data);
4345
$data = $this->assignDataConvertToArray($data);
4446

47+
/**
48+
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay $applePayConfig
49+
*/
50+
$applePayConfig = $this->configProviderMethodFactory->get($this->_code);
51+
$integrationMode = $applePayConfig->getIntegrationMode();
52+
4553
if (isset($data['additional_data']['applepayTransaction'])) {
46-
$applepayEncoded = base64_encode($data['additional_data']['applepayTransaction']);
54+
$transactionData = $data['additional_data']['applepayTransaction'];
55+
56+
$this->validateApplePayTransactionData($transactionData);
4757

58+
$applepayEncoded = base64_encode($transactionData);
4859
$this->getInfoInstance()->setAdditionalInformation('applepayTransaction', $applepayEncoded);
60+
61+
$this->logger2->addDebug(sprintf(
62+
'[Apple Pay] Transaction data assigned for payment. Length: %d characters',
63+
strlen($transactionData)
64+
));
65+
} else {
66+
if ($integrationMode) {
67+
$this->logger2->addError('[Apple Pay SDK Mode] Missing applepayTransaction data in payment assignment - preventing order creation');
68+
69+
throw new Exception(
70+
__('Apple Pay payment failed. No transaction data was received from your device. Please try again or use a different payment method.')
71+
);
72+
} else {
73+
$this->logger2->addDebug('[Apple Pay Redirect Mode] No transaction data in payment assignment - this is expected for redirect mode');
74+
}
4975
}
5076

5177
if (!empty($data['additional_data']['billingContact'])) {
@@ -58,42 +84,141 @@ public function assignData(\Magento\Framework\DataObject $data)
5884
return $this;
5985
}
6086

87+
/**
88+
* Validate Apple Pay transaction data before order creation
89+
*
90+
* @param string $transactionData
91+
* @throws Exception
92+
*/
93+
private function validateApplePayTransactionData($transactionData)
94+
{
95+
/**
96+
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay $applePayConfig
97+
*/
98+
$applePayConfig = $this->configProviderMethodFactory->get($this->_code);
99+
$integrationMode = $applePayConfig->getIntegrationMode();
100+
101+
if ($integrationMode) {
102+
$this->logger2->addDebug('[Apple Pay SDK Mode] Validating client-side transaction data');
103+
104+
if (empty($transactionData) || $transactionData === 'null' || trim($transactionData) === '') {
105+
$this->logger2->addError(sprintf(
106+
'[Apple Pay SDK Mode] Invalid applepayTransaction data before order creation: %s',
107+
var_export($transactionData, true)
108+
));
109+
110+
throw new Exception(
111+
__('Apple Pay payment failed. The transaction data from your device is invalid. Please try again or use a different payment method.')
112+
);
113+
}
114+
115+
$decodedJson = json_decode($transactionData, true);
116+
if (json_last_error() !== JSON_ERROR_NONE || empty($decodedJson['paymentData'])) {
117+
$this->logger2->addError(sprintf(
118+
'[Apple Pay SDK Mode] Invalid JSON in applepayTransaction before order creation. Error: %s, Data: %s',
119+
json_last_error_msg(),
120+
substr($transactionData, 0, 100) . '...'
121+
));
122+
123+
throw new Exception(
124+
__('Apple Pay payment failed. The transaction data format from your device is invalid. Please try again or use a different payment method.')
125+
);
126+
}
127+
128+
$paymentData = $decodedJson['paymentData'];
129+
if (empty($paymentData['data']) || empty($paymentData['signature']) || empty($paymentData['header'])) {
130+
$this->logger2->addError('[Apple Pay SDK Mode] Missing required fields in paymentData before order creation');
131+
132+
throw new Exception(
133+
__('Apple Pay payment failed. The transaction data from your device is incomplete. Please try again or use a different payment method.')
134+
);
135+
}
136+
137+
$this->logger2->addDebug(sprintf(
138+
'[Apple Pay SDK Mode] Valid applepayTransaction data validated before order creation. Length: %d characters',
139+
strlen($transactionData)
140+
));
141+
} else {
142+
$this->logger2->addDebug('[Apple Pay Redirect Mode] Skipping transaction data validation - payment will be processed on Buckaroo hosted page');
143+
144+
if (!empty($transactionData)) {
145+
$this->logger2->addDebug('[Apple Pay Redirect Mode] Unexpected transaction data present - this should be empty for redirect mode');
146+
}
147+
}
148+
}
149+
61150
/**
62151
* {@inheritdoc}
63152
*/
64153
public function getOrderTransactionBuilder($payment)
65154
{
66155
$transactionBuilder = $this->transactionBuilderFactory->get('order');
67156

68-
$requestParameters = [
69-
[
70-
'_' => $payment->getAdditionalInformation('applepayTransaction'),
71-
'Name' => 'PaymentData',
72-
]
73-
];
74-
75-
$billingContact = $payment->getAdditionalInformation('billingContact') ?
76-
json_decode($payment->getAdditionalInformation('billingContact')) : null;
77-
if ($billingContact && !empty($billingContact->givenName) && !empty($billingContact->familyName)) {
78-
$requestParameters[] = [
79-
'_' => $billingContact->givenName . ' ' . $billingContact->familyName,
80-
'Name' => 'CustomerCardName',
157+
/**
158+
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay $applePayConfig
159+
*/
160+
$applePayConfig = $this->configProviderMethodFactory->get($this->_code);
161+
162+
$integrationMode = $applePayConfig->getIntegrationMode();
163+
164+
if ($integrationMode) {
165+
$applepayTransactionData = $payment->getAdditionalInformation('applepayTransaction');
166+
167+
if (empty($applepayTransactionData)) {
168+
$this->logger2->addError(sprintf(
169+
'[Apple Pay SDK Mode] Missing PaymentData for order %s - Client-side transaction processing failed',
170+
$payment->getOrder()->getIncrementId()
171+
));
172+
173+
throw new Exception(
174+
__('Apple Pay payment processing failed. The transaction data from your device could not be processed. Please try again or use a different payment method.')
175+
);
176+
}
177+
178+
$requestParameters = [
179+
[
180+
'_' => $applepayTransactionData,
181+
'Name' => 'PaymentData',
182+
]
81183
];
82-
}
83184

84-
$services = [
85-
'Name' => 'applepay',
86-
'Action' => 'Pay',
87-
'Version' => 0,
88-
'RequestParameter' => $requestParameters,
89-
];
185+
$billingContact = $payment->getAdditionalInformation('billingContact') ?
186+
json_decode($payment->getAdditionalInformation('billingContact')) : null;
187+
if ($billingContact && !empty($billingContact->givenName) && !empty($billingContact->familyName)) {
188+
$requestParameters[] = [
189+
'_' => $billingContact->givenName . ' ' . $billingContact->familyName,
190+
'Name' => 'CustomerCardName',
191+
];
192+
}
90193

91-
/**
92-
* @noinspection PhpUndefinedMethodInspection
93-
*/
94-
$transactionBuilder->setOrder($payment->getOrder())
95-
->setServices($services)
96-
->setMethod('TransactionRequest');
194+
$services = [
195+
'Name' => 'applepay',
196+
'Action' => 'Pay',
197+
'Version' => 0,
198+
'RequestParameter' => $requestParameters,
199+
];
200+
201+
$transactionBuilder->setOrder($payment->getOrder())
202+
->setServices($services)
203+
->setMethod('TransactionRequest');
204+
205+
} else {
206+
$services = [
207+
'Name' => 'applepay',
208+
'Action' => 'Pay',
209+
'Version' => 0,
210+
'RequestParameter' => [],
211+
];
212+
213+
/**
214+
* @noinspection PhpUndefinedMethodInspection
215+
*/
216+
$transactionBuilder->setOrder($payment->getOrder())
217+
->setServices($services)
218+
->setMethod('TransactionRequest');
219+
220+
$transactionBuilder->setCustomVars(['ContinueOnIncomplete' => 'RedirectToHTML']);
221+
}
97222

98223
return $transactionBuilder;
99224
}

Service/Software/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Data
3636
const MODULE_CODE = 'Buckaroo_Magento2';
3737

3838
/** Version of Module */
39-
const BUCKAROO_VERSION = '1.52.0';
39+
const BUCKAROO_VERSION = '1.52.1';
4040

4141
/** @var ProductMetadataInterface */
4242
private $productMetadata;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"docs": "https://docs.buckaroo.io/"
2323
},
2424
"homepage": "https://www.buckaroo.nl",
25-
"version" : "v1.52.0",
25+
"version" : "v1.52.1",
2626
"minimum-stability": "stable",
2727
"autoload": {
2828
"files": [

etc/adminhtml/system/payment_methods/applepay.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@
3030
<config_path>payment/buckaroo_magento2_applepay/active</config_path>
3131
</field>
3232

33+
<field id="integration_mode" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
34+
<label>Apple Pay checkout type</label>
35+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
36+
<frontend_class>admin__field-small</frontend_class>
37+
<comment>Yes = Inline (Integrated in checkout), No = Redirect (Buckaroo Hosted Payment Page)</comment>
38+
<config_path>payment/buckaroo_magento2_applepay/integration_mode</config_path>
39+
</field>
40+
3341
<field id="available_buttons" translate="label comment" type="multiselect" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
3442
<label>Enable or disable applepay buttons</label>
3543
<comment><![CDATA[Select which buttons you want to be active.]]></comment>
3644
<source_model>Buckaroo\Magento2\Model\Config\Source\AvailableButtons</source_model>
3745
<config_path>payment/buckaroo_magento2_applepay/available_buttons</config_path>
3846
<can_be_empty>1</can_be_empty>
47+
<depends>
48+
<field id="integration_mode">1</field>
49+
</depends>
3950
</field>
4051

4152
<field id="title" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@
423423

424424
<buckaroo_magento2_applepay>
425425
<active>0</active>
426+
<integration_mode>1</integration_mode>
426427
<model>Buckaroo\Magento2\Model\Method\Applepay</model>
427428
<order_status>pending</order_status>
428429
<title>Apple Pay</title>

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
-->
2222
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Buckaroo_Magento2:etc/buckaroo_module.xsd">
23-
<module name="Buckaroo_Magento2" setup_version="1.52.0" build_number="1769" stability="stable">
23+
<module name="Buckaroo_Magento2" setup_version="1.52.1" build_number="1769" stability="stable">
2424
<sequence>
2525
<module name="Magento_Payment"/>
2626
<module name="Magento_ReleaseNotification"/>

i18n/de_AT.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@
407407
"Select a month","Wähle einen Monat"
408408
"Select a year","Wählen Sie ein Jahr aus"
409409
"Enable Apple Pay","Apple Pay aktivieren"
410+
"Apple Pay checkout type","Apple Pay Checkout-Typ"
411+
"Yes = Inline (Integrated in checkout), No = Redirect (Buckaroo Hosted Payment Page)", "Yes = Inline (In den Checkout integriert), No = Redirect (Buckaroo Hosted Payment Page)"
410412
"Your payment could not be processed","Ihre Zahlung konnte nicht verarbeitet werden"
411413
"Capayable Postpay","Capayable Nachzahlung"
412414
"Enable In3","In3 aktivieren"

i18n/de_CH.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@
407407
"Select a month","Wähle einen Monat"
408408
"Select a year","Wählen Sie ein Jahr aus"
409409
"Enable Apple Pay","Apple Pay aktivieren"
410+
"Apple Pay checkout type","Apple Pay Checkout-Typ"
411+
"Yes = Inline (Integrated in checkout), No = Redirect (Buckaroo Hosted Payment Page)", "Yes = Inline (In den Checkout integriert), No = Redirect (Buckaroo Hosted Payment Page)"
410412
"Your payment could not be processed","Ihre Zahlung konnte nicht verarbeitet werden"
411413
"Capayable Postpay","Capayable Nachzahlung"
412414
"Enable In3","In3 aktivieren"

i18n/de_DE.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@
407407
"Select a month","Wähle einen Monat"
408408
"Select a year","Wählen Sie ein Jahr aus"
409409
"Enable Apple Pay","Apple Pay aktivieren"
410+
"Apple Pay checkout type","Apple Pay Checkout-Typ"
411+
"Yes = Inline (Integrated in checkout), No = Redirect (Buckaroo Hosted Payment Page)", "Yes = Inline (In den Checkout integriert), No = Redirect (Buckaroo Hosted Payment Page)"
410412
"Your payment could not be processed","Ihre Zahlung konnte nicht verarbeitet werden"
411413
"Capayable Postpay","Capayable Nachzahlung"
412414
"Enable In3","In3 aktivieren"

0 commit comments

Comments
 (0)