forked from plentymarkets/plentyshop-pwa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petrisor Frincu
committed
Aug 13, 2024
1 parent
75800e2
commit 87c1d64
Showing
5 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<template> | ||
<div class="apple-pay-button"></div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ApplepayType } from '~/components/PayPal/types'; | ||
const { loadScript } = usePayPal(); | ||
// const loadApplePay = async () => { | ||
// const scriptElement = document.createElement('script'); | ||
// scriptElement.setAttribute('src', 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js'); | ||
// scriptElement.setAttribute('type', 'text/javascript'); | ||
// document.head.append(scriptElement); | ||
// }; | ||
const canMakePayments = ref(false); | ||
const initiateApplePay = async () => { | ||
try { | ||
const paypal = await loadScript('EUR'); | ||
if (!paypal) { | ||
console.error('Paypal sdk failed'); | ||
return; | ||
} | ||
const applePay = (paypal as any).Applepay() as ApplepayType; | ||
const paymentRequest = applePay.paymentRequest({ | ||
countryCode: 'DE', | ||
currencyCode: 'EUR', | ||
total: { | ||
label: 'Store', | ||
amount: 100, | ||
}, | ||
}); | ||
const paymentSession = applePay.createPaymentSession(paymentRequest); | ||
paymentSession.begin(); | ||
paymentSession.onvalidatemerchant = async (event: any) => { | ||
try { | ||
const validationData = await applePay.validateMerchant({ | ||
validationUrl: event.validationUrl, | ||
}); | ||
paymentSession.completeMerchantValidation(validationData); | ||
} catch (error) { | ||
console.error('Merchant validation failed:', error); | ||
paymentSession.abort(); | ||
} | ||
}; | ||
paymentSession.onpaymentauthorized = async (event: any) => { | ||
try { | ||
const authorization = event.payment; | ||
const paymentResult = await applePay.tokenizePayment(authorization); | ||
if (paymentResult.error) { | ||
throw new Error(paymentResult.error.message); | ||
} | ||
// await props.onPaymentSuccess(paymentResult); | ||
// paymentSession.completePayment(ApplePaySession.STATUS_SUCCESS); | ||
} catch (error) { | ||
console.error('Payment authorization failed:', error); | ||
// props.onPaymentError(error); | ||
// paymentSession.completePayment(ApplePaySession.STATUS_FAILURE); | ||
} | ||
}; | ||
paymentSession.addEventListener('cancel', () => { | ||
console.error('Apple pay cancel'); | ||
}); | ||
} catch (error) { | ||
console.error('Apple pay initiation failed:', error); | ||
} | ||
}; | ||
if (window.ApplePaySession && ApplePaySession.canMakePayments()) { | ||
canMakePayments.value = true; | ||
} | ||
onMounted(() => { | ||
initiateApplePay(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters