Skip to content

Commit

Permalink
Merge pull request #78 from mediaopt/feature/36076-apple-pay
Browse files Browse the repository at this point in the history
#36076 changed the way that passed applePaySession and applepayConfig
  • Loading branch information
majidabbasimediaopt authored Apr 16, 2024
2 parents 51a8370 + 7774968 commit 981f445
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paypal-commercetools-client",
"version": "0.1.5-alpha",
"version": "0.1.6-alpha",
"private": false,
"type": "module",
"license": "MIT",
Expand Down
27 changes: 15 additions & 12 deletions src/components/ApplePay/ApplePayMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
) => {
const [error, setError] = useState<string>();
const [isEligible, setIsEligible] = useState<boolean>(false);
const [applePaySession, setApplePaySession] = useState<ApplePaySession>();
const [applepay, setApplepay] = useState<Applepay>();
const [applepayConfig, setApplepayConfig] = useState<ApplepayConfig>();

let applePaySession: ApplePaySession;
let applepay: Applepay;
let applepayConfig: ApplepayConfig;

const { paymentInfo } = usePayment();

useEffect(() => {
loadScript("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js").then(
async () => {
const applePaySession = window.ApplePaySession;
applePaySession = window.ApplePaySession;
console.log("ApplePaySession", applePaySession);
if (!applePaySession) {
setError("This device does not support Apple Pay");
Expand All @@ -49,15 +50,12 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
return;
}
try {
const applepay = await paypal.Applepay();
applepay = await paypal.Applepay();
console.log("applepay", applepay);
const applepayConfig = await applepay.config();
applepayConfig = await applepay.config();
console.log("applepayConfig", applepayConfig);
if (applepayConfig.isEligible) {
setIsEligible(true);
setApplePaySession(applePaySession);
setApplepay(applepay);
setApplepayConfig(applepayConfig);
}
} catch (error) {
setError("Error while fetching Apple Pay configuration.");
Expand All @@ -67,9 +65,12 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
);
}, [props]);

const onApplePayButtonClicked = () => {
const onApplePayButtonClicked = (
applePaySession: ApplePaySession,
applepayConfig: ApplepayConfig
) => {
console.log("Apple Pay button clicked");
if (!applePaySession || !applepayConfig || !paymentInfo || !applepay) {
if (!applePaySession || !applepayConfig || !paymentInfo) {
console.log("Apple Pay session, config or payment info not available");
return;
}
Expand Down Expand Up @@ -106,7 +107,9 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
<div id="applepay-container">
{isEligible ? (
<button
onClick={onApplePayButtonClicked}
onClick={() =>
onApplePayButtonClicked(applePaySession, applepayConfig)
}
type="button"
className="w-full justify-center text-white bg-primary-900 focus:ring-4 focus:ring-[#050708]/50 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center dark:focus:ring-gray-600 mr-2 mb-2"
>
Expand Down

0 comments on commit 981f445

Please sign in to comment.