Skip to content

Commit 0b28182

Browse files
Merge pull request #1 from amsourav/feature/add-html-message-for-card-fields
feat: add component show to show transaction message
2 parents 2c91bf2 + 6f2157a commit 0b28182

File tree

2 files changed

+16
-4
lines changed
  • advanced-integration/v2/client/react/client
  • standard-integration/client/html/client

2 files changed

+16
-4
lines changed

advanced-integration/v2/client/react/client/App.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

1010
export default function App() {
1111
const [isPaying, setIsPaying] = useState(false);
12+
const [message, setMessage] = useState("");
1213
const initialOptions = {
1314
"client-id": import.meta.env.PAYPAL_CLIENT_ID,
1415
"enable-funding": "venmo",
@@ -126,7 +127,7 @@ export default function App() {
126127
<PayPalScriptProvider options={initialOptions}>
127128
<PayPalButtons
128129
createOrder={createOrder}
129-
onApprove={onApprove}
130+
onApprove={async (data) => setMessage(await onApprove(data))}
130131
onError={onError}
131132
style={{
132133
shape: "rect",
@@ -138,7 +139,7 @@ export default function App() {
138139

139140
<PayPalCardFieldsProvider
140141
createOrder={createOrder}
141-
onApprove={onApprove}
142+
onApprove={async (data) => setMessage(await onApprove(data))}
142143
>
143144
<PayPalCardFieldsForm />
144145
<input
@@ -203,6 +204,7 @@ export default function App() {
203204
/>
204205
</PayPalCardFieldsProvider>
205206
</PayPalScriptProvider>
207+
<Message content={message} />
206208
</div>
207209
);
208210
}
@@ -224,7 +226,7 @@ const SubmitPayment = ({ isPaying, setIsPaying, billingAddress }) => {
224226
}
225227
setIsPaying(true);
226228

227-
cardFieldsForm.submit({ billingAddress }).catch((err) => {
229+
cardFieldsForm.submit({ billingAddress }).finally((err) => {
228230
setIsPaying(false);
229231
});
230232
};
@@ -238,3 +240,7 @@ const SubmitPayment = ({ isPaying, setIsPaying, billingAddress }) => {
238240
</button>
239241
);
240242
};
243+
244+
const Message = ({ content }) => {
245+
return <p>{content}</p>;
246+
};

standard-integration/client/html/client/app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ window.paypal
4242
throw new Error(errorMessage);
4343
} catch (error) {
4444
console.error(error);
45-
// resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
45+
resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
4646
}
4747
},
4848

@@ -98,3 +98,9 @@ window.paypal
9898
},
9999
})
100100
.render("#paypal-button-container");
101+
102+
// Example function to show a result to the user. Your site's UI library can be used instead.
103+
function resultMessage(message) {
104+
const container = document.querySelector("#result-message");
105+
container.innerHTML = message;
106+
}

0 commit comments

Comments
 (0)