From b4e1d3d077e4d8e822199b1334464a6168fcf540 Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Wed, 6 Oct 2021 17:50:28 -0500 Subject: [PATCH 01/19] fix(hostedField): limit the div attributes in types --- src/types/payPalHostedFieldTypes.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/types/payPalHostedFieldTypes.ts b/src/types/payPalHostedFieldTypes.ts index 35c0ce9c..798016d1 100644 --- a/src/types/payPalHostedFieldTypes.ts +++ b/src/types/payPalHostedFieldTypes.ts @@ -1,4 +1,4 @@ -import type { ReactNode, HTMLAttributes } from "react"; +import type { CSSProperties, ReactNode } from "react"; import { PAYPAL_HOSTED_FIELDS_TYPES } from "./enums"; export type PayPalHostedFieldsNamespace = { @@ -31,7 +31,7 @@ export type PayPalHostedFieldOptions = { rejectUnsupportedCards?: boolean; }; -export interface PayPalHostedFieldProps extends HTMLAttributes { +export interface PayPalHostedFieldProps { /** * Represent the hosted field type: [NUMBER, CVV, EXPIRATION_DATE, EXPIRATION_MONTH, EXPIRATION_YEAR, POSTAL_CODE] */ @@ -42,6 +42,12 @@ export interface PayPalHostedFieldProps extends HTMLAttributes { * Check available options in the this type: */ options: PayPalHostedFieldOptions; + id?: string; + className?: string; + lang?: string; + title?: string; + style?: CSSProperties; + align?: string; } export interface PayPalHostedFieldsBillingAddressProps { show: boolean; From 2fd619056c3fee485a38871a46da871837b49357 Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Thu, 7 Oct 2021 12:30:34 -0500 Subject: [PATCH 02/19] feat(hostedFields): example of style uses --- src/stories/PayPalHostedField.stories.tsx | 165 +++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 33a3ee4a..0811a922 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect, useRef } from "react"; import type { FC, ReactElement } from "react"; +import type { Story } from "@storybook/react"; import type { PayPalScriptOptions } from "@paypal/paypal-js/types/script-options"; @@ -26,6 +27,10 @@ const scriptProviderOptions: PayPalScriptOptions = { components: "buttons,hosted-fields", ...getOptionsFromQueryString(), }; +const customBorderFieldStyle = { + border: "1px solid #606060", + boxShadow: "2px 2px 10px 2px #606060", +}; /** * Get dynamically the capture order URL to fetch the payment info @@ -87,11 +92,14 @@ const SubmitPayment = () => { return ( <> + + + ); + }; + + return ( + + fetch(CREATE_ORDER_URL, { + method: "post", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + purchase_units: [ + { + amount: { + value: 50, + currency_code: "USD", + }, + }, + ], + intent: "CAPTURE", + }), + }) + .then((response) => response.json()) + .then((order) => order.id) + .catch((err) => { + alert(err); + }) + } + notEligibleError={} + styles={{ + ".valid": { color: "#28a745" }, + ".invalid": { color: "#dc3545" }, + "input": { "font-family": "monospace", "font-size": "16px" } + }} + > + + + + + + + {/* Custom client component to handle hosted fields submit */} + + + ); +} + `, + }, + }, +}; + export const ExpirationDate: FC = () => { return ( Date: Thu, 7 Oct 2021 12:36:36 -0500 Subject: [PATCH 03/19] docs(hostedFields): minor edit --- src/stories/PayPalHostedField.stories.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 0811a922..47b3b28e 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -384,7 +384,6 @@ export const Default: FC = () => { placeholder: "MM/YYYY", }} /> - {/* Custom client component to handle hosted fields submit */} ); From 9e4f7ba0c42537b92e23975fbc6739d68f57095d Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Thu, 7 Oct 2021 15:56:15 -0500 Subject: [PATCH 04/19] docs(hostedField): avoid submit an invalid payment form --- src/stories/PayPalHostedField.stories.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 47b3b28e..8a5bfac6 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -58,15 +58,22 @@ const SubmitPayment = () => { const hostedField = usePayPalHostedFields(); const handleClick = () => { - if ( - hostedField && - cardHolderName.current && - cardHolderName.current.value - ) { + if (hostedField) { + if ( + Object.values(hostedField.getState().fields).some( + (field) => !field.isValid + ) || + cardHolderName?.current?.value + ) { + return alert( + "The payment form is invalid, please check it before execute the payment" + ); + } + setPaying(true); hostedField .submit({ - cardholderName: cardHolderName.current.value, + cardholderName: cardHolderName?.current?.value, }) .then((data) => { console.log("orderId: ", data.orderId); @@ -86,6 +93,7 @@ const SubmitPayment = () => { }) .catch((err) => { alert(JSON.stringify(err)); + setPaying(false); }); } }; From 1bd9f2e7a0a95b4fdb297188c8738d0537c0a5d2 Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Thu, 7 Oct 2021 16:00:25 -0500 Subject: [PATCH 05/19] docs(hostedFields): minor edits --- src/stories/PayPalHostedField.stories.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 8a5bfac6..4f34e43d 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -63,7 +63,7 @@ const SubmitPayment = () => { Object.values(hostedField.getState().fields).some( (field) => !field.isValid ) || - cardHolderName?.current?.value + !cardHolderName?.current?.value ) { return alert( "The payment form is invalid, please check it before execute the payment" @@ -279,11 +279,17 @@ export const Default: FC = () => { const hostedField = usePayPalHostedFields(); const handleClick = () => { - if ( - hostedField && - cardHolderName.current && - cardHolderName.current.value - ) { + if (hostedField) { + if ( + Object.values(hostedField.getState().fields) + .some((field) => !field.isValid) || + !cardHolderName?.current?.value + ) { + return alert( + "The payment form is invalid, please check it before execute the payment" + ); + } + hostedField .submit({ cardholderName: cardHolderName.current.value, From 088f5225b2d355241a9c74e040509b7eb9a9cf16 Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Thu, 7 Oct 2021 16:40:07 -0500 Subject: [PATCH 06/19] docs(hostedFields): fix custom styles --- src/stories/PayPalHostedField.stories.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 4f34e43d..51d0f6e9 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useEffect, useRef, CSSProperties } from "react"; import type { FC, ReactElement } from "react"; import type { Story } from "@storybook/react"; @@ -29,7 +29,7 @@ const scriptProviderOptions: PayPalScriptOptions = { }; const customBorderFieldStyle = { border: "1px solid #606060", - boxShadow: "2px 2px 10px 2px #606060", + boxShadow: "2px 2px 10px 2px rgba(0,0,0,0.1)", }; /** @@ -52,7 +52,7 @@ const NotEligibleError = () => ( /** * Functional component to submit the hosted fields form */ -const SubmitPayment = () => { +const SubmitPayment = ({ customStyle }: { customStyle?: CSSProperties }) => { const [paying, setPaying] = useState(false); const cardHolderName = useRef(null); const hostedField = usePayPalHostedFields(); @@ -106,6 +106,7 @@ const SubmitPayment = () => { @@ -264,7 +265,7 @@ export const Default: FC = () => { }} /> {/* Custom client component to handle hosted fields submit */} - + ); }; From 6fd5a4ef2c800d73590e8b9b7e32a4406ff898b3 Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Thu, 7 Oct 2021 16:43:27 -0500 Subject: [PATCH 07/19] docs(storybook): remove outline in custom input field --- src/stories/PayPalHostedField.stories.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 51d0f6e9..5eb4f717 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -106,7 +106,7 @@ const SubmitPayment = ({ customStyle }: { customStyle?: CSSProperties }) => { From 3da001a187c77f2cd75379dc475a0ec2979bfe3d Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Thu, 7 Oct 2021 16:50:22 -0500 Subject: [PATCH 08/19] docs(hostedFields): fixed comments --- src/stories/PayPalHostedField.stories.tsx | 29 +++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 5eb4f717..69d1d62e 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -21,6 +21,7 @@ import { const uid = generateRandomString(); const TOKEN_URL = `${HEROKU_SERVER}/api/paypal/hosted-fields/auth`; const CREATE_ORDER_URL = `${HEROKU_SERVER}/api/paypal/checkout/orders`; +const RED_COLOR = "#dc3545"; const scriptProviderOptions: PayPalScriptOptions = { "client-id": "AdOu-W3GPkrfuTbJNuW9dWVijxvhaXHFIRuKrLDwu14UDwTTHWMFkUwuu9D8I1MAQluERl9cFOd7Mfqe", @@ -124,15 +125,6 @@ const SubmitPayment = ({ customStyle }: { customStyle?: CSSProperties }) => { export default { title: "Example/PayPalHostedFields", component: PayPalHostedField, - parameters: { - docs: { - default: { - source: { - code: "djhfhjfh", - }, - }, - }, - }, argTypes: { PayPalHostedFieldOptions: { control: { type: "null" }, @@ -220,12 +212,12 @@ export const Default: FC = () => { notEligibleError={} styles={{ ".valid": { color: "#28a745" }, - ".invalid": { color: "#dc3545" }, + ".invalid": { color: RED_COLOR }, input: { "font-family": "monospace", "font-size": "16px" }, }} > { }} /> { }} /> { source: { code: ` () => { + const RED_COLOR_STYLE = { color: "#dc3545" }; const SubmitPayment = () => { const cardHolderName = useRef(null); const hostedField = usePayPalHostedFields(); @@ -361,11 +354,11 @@ export const Default: FC = () => { notEligibleError={} styles={{ ".valid": { color: "#28a745" }, - ".invalid": { color: "#dc3545" }, + ".invalid": RED_COLOR_STYLE, "input": { "font-family": "monospace", "font-size": "16px" } }} > - + { placeholder: "4111 1111 1111 1111", }} /> - + { maskInput: true, }} /> - + { notEligibleError={} styles={{ ".valid": { color: "#28a745" }, - ".invalid": { color: "#dc3545" }, + ".invalid": { color: RED_COLOR }, }} > Date: Fri, 8 Oct 2021 09:49:02 -0500 Subject: [PATCH 09/19] docs(hostedFields): constants variables --- .../PayPalHostedFieldsProvider.tsx | 2 +- src/stories/PayPalHostedField.stories.tsx | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/hostedFields/PayPalHostedFieldsProvider.tsx b/src/components/hostedFields/PayPalHostedFieldsProvider.tsx index 347fd81c..b9ed6dd8 100644 --- a/src/components/hostedFields/PayPalHostedFieldsProvider.tsx +++ b/src/components/hostedFields/PayPalHostedFieldsProvider.tsx @@ -32,7 +32,7 @@ export const PayPalHostedFieldsProvider: FC = const hostedFieldsContainerRef = useRef(null); const hostedFields = useRef(); const [, setErrorState] = useState(null); - + console.log("***", childrenList); /** * Executed on the mount process to validate the children */ diff --git a/src/stories/PayPalHostedField.stories.tsx b/src/stories/PayPalHostedField.stories.tsx index 69d1d62e..e8d94cf1 100644 --- a/src/stories/PayPalHostedField.stories.tsx +++ b/src/stories/PayPalHostedField.stories.tsx @@ -22,6 +22,7 @@ const uid = generateRandomString(); const TOKEN_URL = `${HEROKU_SERVER}/api/paypal/hosted-fields/auth`; const CREATE_ORDER_URL = `${HEROKU_SERVER}/api/paypal/checkout/orders`; const RED_COLOR = "#dc3545"; +const GREEN_COLOR = "#28a745"; const scriptProviderOptions: PayPalScriptOptions = { "client-id": "AdOu-W3GPkrfuTbJNuW9dWVijxvhaXHFIRuKrLDwu14UDwTTHWMFkUwuu9D8I1MAQluERl9cFOd7Mfqe", @@ -103,14 +104,15 @@ const SubmitPayment = ({ customStyle }: { customStyle?: CSSProperties }) => { <> -