Skip to content

Commit cf722e3

Browse files
committed
Move monero component to order confirmation page
1 parent b48dd8f commit cf722e3

File tree

12 files changed

+170
-78
lines changed

12 files changed

+170
-78
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ Copyright (C) 2019-Present BigCommerce Inc. All rights reserved.
8383

8484
## Monero
8585

86-
![alt text](https://i.ibb.co/6nJ2GFj/Screenshot.png)
86+
![alt text](https://i.ibb.co/6XDCKH1/2-1.png)
87+
![alt text](https://i.ibb.co/Y7K2srY/1-1.png)

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"react-media": "^1.10.0",
8484
"react-modal": "^3.8.1",
8585
"react-popper": "^1.3.2",
86+
"react-qr-code": "^2.0.15",
8687
"react-transition-group": "^2.5.3",
8788
"reselect": "^4.1.7",
8889
"shallowequal": "^1.1.0",

packages/core/src/app/customer/CheckoutButtonList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const SUPPORTED_METHODS: string[] = [
3434
'googlepaystripe',
3535
'googlepaystripeupe',
3636
'googlepayworldpayaccess',
37+
'monero'
3738
];
3839

3940
export interface CheckoutButtonListProps {

packages/core/src/app/customer/getSupportedMethods.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const SUPPORTED_METHODS: string[] = [
2626
'googlepayworldpayaccess',
2727
'googlepaypaypalcommerce',
2828
'googlepaytdonlinemart',
29+
'monero'
2930
];
3031

3132
export const getSupportedMethodIds = (methodIds: string[]): string[] => {

packages/core/src/app/order/OrderConfirmation.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import OrderConfirmationSection from './OrderConfirmationSection';
4242
import OrderStatus from './OrderStatus';
4343
import PrintLink from './PrintLink';
4444
import ThankYouHeader from './ThankYouHeader';
45+
import { MoneroPaymentMethod } from './monero/MoneroPaymentMethod';
4546

4647
const OrderSummary = lazy(() =>
4748
retry(
@@ -132,6 +133,12 @@ class OrderConfirmation extends Component<
132133
links: { siteLink },
133134
} = config;
134135

136+
let isMonero = false;
137+
138+
if (order?.payments?.at(0)?.providerId === "instore") {
139+
isMonero = true;
140+
}
141+
135142
return (
136143
<div
137144
className={classNames('layout optimizedCheckout-contentPrimary', {
@@ -150,14 +157,18 @@ class OrderConfirmation extends Component<
150157
/>
151158

152159
{paymentInstructions && (
153-
<OrderConfirmationSection>
154-
<div
155-
dangerouslySetInnerHTML={{
156-
__html: DOMPurify.sanitize(paymentInstructions),
157-
}}
158-
data-test="payment-instructions"
159-
/>
160-
</OrderConfirmationSection>
160+
161+
isMonero ?
162+
<MoneroPaymentMethod order={order} />
163+
:
164+
<OrderConfirmationSection>
165+
<div
166+
dangerouslySetInnerHTML={{
167+
__html: DOMPurify.sanitize(paymentInstructions),
168+
}}
169+
data-test="payment-instructions"
170+
/>
171+
</OrderConfirmationSection>
161172
)}
162173

163174
{this.renderGuestSignUp({

packages/core/src/app/payment/paymentMethod/MoneroPaymentMethod.scss renamed to packages/core/src/app/order/monero/MoneroPaymentMethod.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
.main {
22

3+
.monero-text{
4+
font-weight: 500;
5+
font-size: 24px;
6+
}
7+
38
.address{
49
margin-bottom: 10px;
510
white-space: initial;
611
line-break: anywhere;
712
resize: none;
813
}
914

15+
.amount {
16+
margin-bottom: 10px;
17+
}
18+
1019
.QR {
1120
display: block;
1221
width: 100%;
@@ -16,4 +25,15 @@
1625
margin-bottom: 20px;
1726
margin-top: 30px;
1827
}
28+
29+
.state{
30+
text-transform: capitalize;
31+
}
32+
33+
.openwallet{
34+
margin-top: 20px;
35+
text-decoration: underline;
36+
text-align: center;
37+
display: block;
38+
}
1939
}

packages/core/src/app/payment/paymentMethod/MoneroPaymentMethod.tsx renamed to packages/core/src/app/order/monero/MoneroPaymentMethod.tsx

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
import React, { useEffect, useState } from 'react'
22
import './MoneroPaymentMethod.scss';
33
import { LoadingSpinner } from '@bigcommerce/checkout/ui';
4-
import { createCheckoutService } from '@bigcommerce/checkout-sdk';
4+
import { Order } from '@bigcommerce/checkout-sdk';
55
import QRCode from 'react-qr-code';
66

7+
enum PaymentState {
8+
unpaid,
9+
pending,
10+
paid,
11+
withdrawn,
12+
refunded,
13+
expired,
14+
deleted
15+
}
16+
717
interface CreatePaymentRequest {
8-
checkoutId: string;
9-
amount: number;
10-
currency: string;
11-
email: string;
18+
orderId: number;
1219
}
1320

1421
interface CreatePaymentResponse {
15-
paymentId: string;
22+
orderId: number;
1623
xmrAmount: number;
1724
address: string;
18-
walletURI: string;
19-
qrLink: string;
25+
paymentState: PaymentState;
26+
}
27+
28+
interface MoneroPaymentMethodProps {
29+
order: Order;
2030
}
2131

22-
export function MoneroPaymentMethod(props: any) {
32+
export function MoneroPaymentMethod({ order }: MoneroPaymentMethodProps) {
2333
const [loading, setLoading] = useState(false);
2434
const [paymentResponse, setPaymentResponse] = useState<CreatePaymentResponse | null>(null);
2535
const [paymentLink, setPaymentLink] = useState("");
36+
const [error, setError] = useState("");
2637

27-
console.log(props)
38+
useEffect(() => {
39+
(async () => {
40+
await getPaymentDetails();
41+
})();
42+
}, []);
2843

2944
useEffect(() => {
30-
// Try to fetch existing payment by checkoutId
31-
}, [])
45+
const interval = setInterval(getPaymentDetails, 120000);
46+
return () => { clearInterval(interval); }
47+
}, [paymentResponse]);
3248

33-
const createPaymentAddress = async () => {
49+
const getPaymentDetails = async () => {
3450
setLoading(true);
3551

3652
try {
37-
const service = createCheckoutService();
38-
// const state = await service.loadCheckout(checkoutId);
39-
40-
const checkoutSelectors = await service.loadCheckout(service.getState().data.getCheckout()?.id)
41-
42-
const checkout = checkoutSelectors.data.getCheckout();
43-
44-
if (!checkout) return;
45-
46-
console.log(checkout?.grandTotal)
47-
console.log(checkout?.id)
48-
console.log(checkout?.cart.currency.code)
49-
console.log(checkout?.customer.email)
50-
5153
const createPaymentRequest: CreatePaymentRequest = {
52-
amount: checkout.grandTotal,
53-
checkoutId: checkout.id,
54-
email: checkout.customer.email,
55-
currency: checkout.cart.currency.code
54+
orderId: order.orderId,
5655
}
5756

57+
// TODO Configable
5858
const response = await fetch("http://localhost:5025/api" + "/payments", {
5959
method: "POST",
6060
body: JSON.stringify(createPaymentRequest),
@@ -65,7 +65,7 @@ export function MoneroPaymentMethod(props: any) {
6565
});
6666

6767
if (!response.ok) {
68-
// setError(await response.json());
68+
setError(await response.json());
6969
return;
7070
}
7171

@@ -85,19 +85,28 @@ export function MoneroPaymentMethod(props: any) {
8585

8686
return (
8787
<div className='main'>
88-
<button type='button' onClick={createPaymentAddress} className='button'>Create a one-time payment address</button>
89-
<LoadingSpinner isLoading={loading}></LoadingSpinner>
88+
<p className='monero-text'>Pay with Monero</p>
89+
<LoadingSpinner isLoading={loading}/>
9090
{
9191
paymentResponse &&
9292
<div>
9393
<label htmlFor='address'>Address</label>
9494
<textarea readOnly rows={2} name='address' id='address' className='form-input optimizedCheckout-form-input address' value={paymentResponse.address}/>
9595
<label htmlFor='amount'>Amount</label>
9696
<input readOnly name='amount' id='amount' className='form-input optimizedCheckout-form-input amount' value={paymentResponse.xmrAmount}/>
97-
98-
<QRCode className="QR" value={paymentLink}></QRCode>
97+
<label htmlFor='state'>Status</label>
98+
<input readOnly name='state' id='state' className='form-input optimizedCheckout-form-input state' value={PaymentState[paymentResponse.paymentState]}/>
99+
100+
<QRCode className="QR" value={paymentLink}/>
101+
<a className="openwallet" href={paymentLink}>Open Monero wallet</a>
99102
</div>
100103
}
104+
{
105+
error !== "" ?
106+
<></>
107+
:
108+
<></>
109+
}
101110
</div>
102111
);
103112

packages/core/src/app/payment/Payment.tsx

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -608,35 +608,40 @@ export function mapToPaymentProps({
608608

609609
const { isComplete = false } = getOrder() || {};
610610

611-
const monero = {
612-
id: 'monero',
613-
gateway: undefined,
614-
logoUrl: "",
615-
method: 'monero',
616-
supportedCards: [],
617-
initializationData: null,
618-
initializationStrategy: { type: "not_applicable" },
619-
config: {
620-
cardCode: false,
621-
displayName: 'Monero',
622-
enablePaypal: undefined,
623-
hasDefaultStoredInstrument: false,
624-
helpText: '',
625-
is3dsEnabled: undefined,
626-
isHostedFormEnabled: false,
627-
isVaultingCvvEnabled: false,
628-
isVaultingEnabled: false,
629-
isVisaCheckoutEnabled: undefined,
630-
requireCustomerCode: false,
631-
merchantId: undefined,
632-
testMode: false,
633-
},
634-
type: "PAYMENT_TYPE_OFFLINE"
635-
} as PaymentMethod
636-
637-
let methods: PaymentMethod[] = [monero, ...(getPaymentMethods() || EMPTY_ARRAY)];
638-
639-
console.log(methods)
611+
// const monero = {
612+
// id: 'monero',
613+
// gateway: null!,
614+
// logoUrl: "",
615+
// method: 'offline',
616+
// supportedCards: [],
617+
// initializationData: null,
618+
// initializationStrategy: { type: "not_applicable" },
619+
// clientToken: null!,
620+
// returnUrl: null!,
621+
// config: {
622+
// cardCode: null!,
623+
// displayName: 'Monero',
624+
// enablePaypal: null!,
625+
// hasDefaultStoredInstrument: false,
626+
// helpText: '',
627+
// is3dsEnabled: null!,
628+
// isHostedFormEnabled: false,
629+
// isVaultingCvvEnabled: false,
630+
// isVaultingEnabled: false,
631+
// isVisaCheckoutEnabled: null!,
632+
// requireCustomerCode: false,
633+
// merchantId: null!,
634+
// testMode: false,
635+
// showCardHolderName: null!,
636+
// logo: null!
637+
// },
638+
// nonce: null!,
639+
// type: "PAYMENT_TYPE_OFFLINE"
640+
// } as PaymentMethod
641+
642+
// let methods: PaymentMethod[] = [monero, ...(getPaymentMethods() || EMPTY_ARRAY)];
643+
644+
let methods: PaymentMethod[] = [...(getPaymentMethods() || EMPTY_ARRAY)];
640645

641646
// TODO: In accordance with the checkout team, this functionality is temporary and will be implemented in the backend instead.
642647
if (paymentProviderCustomer?.stripeLinkAuthenticationState) {

0 commit comments

Comments
 (0)