Skip to content

Commit

Permalink
Merge pull request #91 from mediaopt/feature/36076-apple-pay
Browse files Browse the repository at this point in the history
#36076 Added applePayDisplayName to ApplePay component
  • Loading branch information
majidabbasimediaopt authored Apr 18, 2024
2 parents b2e2601 + 1e1674a commit a8841bc
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 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.18-alpha",
"version": "0.1.19-alpha",
"private": false,
"type": "module",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function App() {
components: "applepay,buttons",
buyerCountry: "US",
}}
applePayDisplayName="My Store"
/>
),
Venmo: (
Expand Down
4 changes: 2 additions & 2 deletions src/components/ApplePay/ApplePay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from "react";
import { RenderTemplate } from "../RenderTemplate";
import { ApplePayButton } from "./ApplePayButton";

import { SmartComponentsProps } from "../../types";
import { ApplePayComponentsProps } from "../../types";

export const ApplePay: React.FC<SmartComponentsProps> = ({
export const ApplePay: React.FC<ApplePayComponentsProps> = ({
options,

createPaymentUrl,
Expand Down
9 changes: 6 additions & 3 deletions src/components/ApplePay/ApplePayButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { useHandleCreatePayment } from "../../app/useHandleCreatePayment";

import { ApplePayMask } from "./ApplePayMask";

type CustomPayPalButtonsComponentProps = PayPalButtonsComponentProps & {
enableVaulting?: boolean;
};
import { ApplePayProps } from "../../types";

type CustomPayPalButtonsComponentProps = ApplePayProps &
PayPalButtonsComponentProps & {
enableVaulting?: boolean;
};

export const ApplePayButton: React.FC<CustomPayPalButtonsComponentProps> = (
props
Expand Down
15 changes: 9 additions & 6 deletions src/components/ApplePay/ApplePayMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";

import loadScript from "../../app/loadScript";
import { usePayment } from "../../app/usePayment";
import { CustomPayPalButtonsComponentProps } from "../../types";
import { CustomPayPalButtonsComponentProps, ApplePayProps } from "../../types";
import { ERROR_TEXT_STYLE } from "../../styles";

declare const window: any;
Expand Down Expand Up @@ -40,9 +40,10 @@ type Applepay = {
validateMerchant: ({}: ApplepayValidateMerchant) => Promise<ApplepayValidateMerchantResult>;
};

export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
props
) => {
type ApplePayMaskComponentProps = ApplePayProps &
CustomPayPalButtonsComponentProps;

export const ApplePayMask: React.FC<ApplePayMaskComponentProps> = (props) => {
const [logs, setLogs] = useState<string>();
const [paymentId, setPaymentId] = useState<string>();

Expand All @@ -53,6 +54,8 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (

const { paymentInfo, handleCreateOrder, handleOnApprove } = usePayment();

const { applePayDisplayName } = props;

useEffect(() => {
loadScript("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js").then(
async () => {
Expand Down Expand Up @@ -105,7 +108,7 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
currencyCode: paymentInfo.currency,
requiredBillingContactFields: ["postalAddress"],
total: {
label: "Demo",
label: applePayDisplayName,
type: "final",
amount: paymentInfo.amount,
},
Expand All @@ -119,7 +122,7 @@ export const ApplePayMask: React.FC<CustomPayPalButtonsComponentProps> = (
try {
const validateResult = await pay.validateMerchant({
validationUrl: event.validationURL,
displayName: "My Store",
displayName: applePayDisplayName,
});

console.log("onvalidatemerchant validateResult", validateResult);
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export type CustomPayPalButtonsComponentProps = Omit<
export type SmartComponentsProps = CustomPayPalButtonsComponentProps &
GeneralComponentsProps;

export type ApplePayProps = {
applePayDisplayName: string;
};

export type ApplePayComponentsProps = ApplePayProps & SmartComponentsProps;

export type CartInformation = {
account: {
email: string;
Expand Down

0 comments on commit a8841bc

Please sign in to comment.