Skip to content

Commit

Permalink
apple pay
Browse files Browse the repository at this point in the history
  • Loading branch information
LucSPI committed May 24, 2023
1 parent 471e90b commit 1dfcbf7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/components/Detail/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BalanceIcon, WithdrawIcon, Visa, MasterCard, PaypalIcon, ApplepayIcon,
import { Button, Radio } from "~/components/UI";
import { BsPlusLg } from 'react-icons/bs'
import { ReactNode, useState } from "react";
import { Stripe } from "./Payments";
import { Applepay, Stripe } from "./Payments";
import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";

Expand Down Expand Up @@ -32,7 +32,9 @@ const Deposit: React.FC = () => {
const selectPaymentMethod = (value: string) => {
setUsedMethod(value);
}



const paymentList: paymentListProps[] = [
{
text:"Credit Card / Debit Card",
Expand Down Expand Up @@ -98,10 +100,19 @@ const Deposit: React.FC = () => {
</div>
</div>
<div className={`w-0.5 h-[290px] bg-[#B4C7D8] col-span-1 ${top && usedMethod === 'stripe' ? "block" : "hidden"}`}></div>
<div className={`col-span-3 ${top && usedMethod === 'stripe' ? "block" : "hidden"}`}>
<div className={`col-span-3`}>
<Elements stripe={stripePromise}>
<Stripe />
{
top && usedMethod === 'stripe' ?
<Stripe />
:
top && usedMethod === 'apple' ?
<Applepay />
:
''
}
</Elements>

</div>
</div>
<div className="mt-10">
Expand Down
51 changes: 51 additions & 0 deletions src/components/Detail/Payments/Applepay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useState, useEffect } from "react";
import { useStripe, PaymentRequestButtonElement } from "@stripe/react-stripe-js";

export const Applepay = () => {
const stripe = useStripe() as any;
const [paymentRequest, setPaymentRequest] = useState<any>(null);
useEffect(() => {
if (stripe) {
const pr = stripe.paymentRequest({
country: "US",
currency: "usd",
total: {
label: "Membership",
amount: 2000,
},
requestPayerName: false,
requestPayerEmail: false,
// disableWallets: ["googlePay", "browserCard"],
});

pr.canMakePayment().then((result: any) => {
console.warn(result);
if (result) {
setPaymentRequest(pr);
}
});
}
},[stripe]);

const onPaymentSubmit = () => {
paymentRequest.on("paymentmethod", handlePaymentRequest);
};
const handlePaymentRequest = async (event: any) => {
console.warn(event);
}

return (
<>
<form>
{
paymentRequest && (
<PaymentRequestButtonElement
options={{ paymentRequest }}
onClick={onPaymentSubmit}
/>
)
}
</form>
</>
)
}
3 changes: 2 additions & 1 deletion src/components/Detail/Payments/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Stripe';
export * from './Stripe';
export * from './Applepay';

0 comments on commit 1dfcbf7

Please sign in to comment.