Skip to content

Commit

Permalink
Merge pull request #52 from buckaroo-it/BP-3811-Apple-Pay-PaymentData…
Browse files Browse the repository at this point in the history
…-missing

Bp 3811 apple pay payment data missing
  • Loading branch information
AlbinaBaraliu authored Dec 4, 2024
2 parents 0b27046 + ed7f5dd commit 1f91603
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 183 deletions.
10 changes: 4 additions & 6 deletions Magewire/Payment/Method/Applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public function updateData(string $paymentData, string $billingContact)
{
try {
$quote = $this->sessionCheckout->getQuote();
$quote->getPayment()->setAdditionalInformation('applepayTransaction', $paymentData);
$applePayEncoded = base64_encode($paymentData);
$quote->getPayment()->setAdditionalInformation('applepayTransaction', $applePayEncoded);
$quote->getPayment()->setAdditionalInformation('billingContact', $billingContact);

$this->quoteRepository->save($quote);
} catch (LocalizedException $exception) {
$this->dispatchErrorMessage($exception->getMessage());
}
return $paymentData;
}
public function evaluateCompletion(EvaluationResultFactory $resultFactory): EvaluationResultInterface
{
Expand All @@ -96,13 +98,10 @@ public function evaluateCompletion(EvaluationResultFactory $resultFactory): Eval
} catch (LocalizedException $exception) {
$this->dispatchErrorMessage($exception->getMessage());
}



return $resultFactory->createSuccess();
}

public function getJsSdkUrl(): string
public function getJsSdkUrl()
{
try {
return $this->assetRepo->getUrl('Buckaroo_HyvaCheckout::js/applepay.js');
Expand Down Expand Up @@ -149,7 +148,6 @@ private function getTotalLines(): array
];
}
}

return $totals;
}

Expand Down
3 changes: 3 additions & 0 deletions view/frontend/layout/hyva_checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
layout="checkout"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"
>
<head>
<script src="Buckaroo_HyvaCheckout::js/hide-applepay.js" />
</head>
<body>
<referenceContainer name="hyva.checkout.api-v1.after">
<block name="checkout.buckaroo_after_api-v1"
Expand Down
31 changes: 18 additions & 13 deletions view/frontend/templates/component/payment/after.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@
})
},

formatTransactionResponse(response) {
async formatTransactionResponse(response) {
if (response === null || response === 'undefined') {
return null;
}

const paymentData = response.token.paymentData;
const paymentData = response.token.paymentData;

return JSON.stringify({
paymentData: {
return JSON.stringify({
paymentData: {
version: paymentData.version,
data: paymentData.data,
signature: paymentData.signature,
Expand All @@ -237,13 +237,16 @@
publicKeyHash: paymentData.header.publicKeyHash,
transactionId: paymentData.header.transactionId,
},
},
});
},
});
},

async captureFunds(payment) {

const billingContact = payment && payment.billingContact ? JSON.stringify(payment.billingContact) : ''
await this.$wire.updateData(this.formatTransactionResponse(payment),billingContact);

const formattedData = await this.formatTransactionResponse(payment);
await this.$wire.updateData(formattedData,billingContact);
this.resolve();
return {
status: window.ApplePaySession.STATUS_SUCCESS,
Expand All @@ -252,6 +255,7 @@
},

async beginPayment() {

const promise = new Promise((resolve) => {
this.resolve = resolve;

Expand All @@ -268,8 +272,8 @@
(payment) => this.captureFunds(payment),
null,
null,
['email', 'postalAddress'],
['email']
["name", "postalAddress", "phone"],
["name", "postalAddress", "phone"]
);
new BuckarooApplePay.PayPayment(config).beginPayment()
})
Expand All @@ -279,13 +283,14 @@
async submit() {
await hyvaCheckout.order.place();
},
getButtonClass() {
return `pay-with-apple ${BuckarooApplePay.getButtonClass(this.config.buttonStyle, 'buy')}`;
},
// getButtonClass() {
// return `pay-with-apple ${BuckarooApplePay.getButtonClass(this.config.buttonStyle, 'buy')}`;
// },
async register() {
this.config = this.$wire.get('config');
window.merchantIdentifier = this.config.guid;
this.loadSdk().then(async () => {
this.canDisplay = await BuckarooApplePay.checkPaySupport();
this.canDisplay = await BuckarooApplePay.checkPaySupport(this.config.guid);
window.buckarooTask = async () => {
if(this.canDisplay)
await this.beginPayment();
Expand Down
18 changes: 9 additions & 9 deletions view/frontend/templates/component/payment/method/applepay.phtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

declare(strict_types=1);
/** @var Escaper $escaper */
/** @var \Buckaroo\HyvaCheckout\Magewire\Checkout\Payment\Method\Applepay $magewire */
declare(strict_types=1);
/** @var Escaper $escaper */
/** @var \Buckaroo\HyvaCheckout\Magewire\Checkout\Payment\Method\Applepay $magewire */

use Magento\Framework\Escaper;
use Magento\Framework\Escaper;
?>
<form x-data="buckaroo.applePay('<?= $magewire->getJsSdkUrl() ?>')" x-init="register()" novalidate>
<template x-if="canDisplay">
<button type="button" :class="getButtonClass()" @click="submit()">
<?= $escaper->escapeHtml(__('Place Order')) ?>
</button>
</template>
<!-- <template x-if="canDisplay">-->
<!-- <button type="button" :class="getButtonClass()" @click="submit">-->
<!-- --><?php //= $escaper->escapeHtml(__('Place Order')) ?>
<!-- </button>-->
<!-- </template>-->
</form>
Loading

0 comments on commit 1f91603

Please sign in to comment.