Skip to content

Commit 99ecbdc

Browse files
Merge pull request #2 from hyva-themes/improvements
Minor improvements
2 parents 3538148 + cc119aa commit 99ecbdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+505
-380
lines changed

README.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,53 @@ File: `src/reactapp/package.json`
2020
```
2121
"config": {
2222
"paymentMethodsRepo": {
23-
"amazon_payment_v2": "[email protected]:hyva-themes/magento2-react-checkout-amazon-pay.git"
23+
"amazonPay": "[email protected]:hyva-themes/magento2-react-checkout-amazon-pay.git"
2424
}
2525
},
2626
```
2727
With this code in `package.json` and running `npm install`, then you are all set. This repo will be copied into the React Checkout and configured correctly.
2828

2929
Finally, we need to build the app again. For this, you need to run `npm run build` from the root directory of React Checkout react app (`src/reactapp`). After this, if you navigate to the checkout page from your site, then you will see the Amazon Pay payment option you have configured in the above step.
3030

31+
## Pass Amazon Pay configuration to Hyvä React Checkout
32+
33+
It is important to pass the amazon pay related checkout configurations to the `CheckoutConfigProvider` ViewModel. You can use the module https://github.com/rajeev-k-tomy/hyva-react-checkout-amazon-pay for this purpose or try to implement it by your own way.
34+
35+
## Translations
36+
37+
In order to incorparate translations related to this payment integration, update react app traslation directory `src/i18n` with necessary translations provided inside `i18n` directory.
38+
39+
Along with that, add below code in the layout xml file given below:
40+
41+
File: `src/view/frontend/layout/hyvareactcheckout_reactcheckout_index.`xml`
42+
43+
```
44+
<?xml version="1.0"?>
45+
<page>
46+
...
47+
<body>
48+
...
49+
<referenceContainer name="main" htmlClass="container column main">
50+
<referenceContainer name="content">
51+
<referenceBlock name="checkout.translations">
52+
<arguments>
53+
<argument name="checkout_translations" xsi:type="array">
54+
<item name="hyva_reactcheckout_amazon_pay" xsi:type="string">
55+
<![CDATA["The shipping address you have set on Amazon is not valid for the current store, please set another address","The billing address you have set on Amazon is not valid for the current store, please set another address.",Amazon pay not available,Amazon Pay]]>
56+
</item>
57+
</argument>
58+
</arguments>
59+
</referenceBlock>
60+
...
61+
</referenceContainer>
62+
</referenceContainer>
63+
....
64+
</body>
65+
</page>
66+
```
67+
68+
69+
3170
## Documentation
3271

3372
- If you need information on the build process of the React Checkout, then you can **[read more about it here](https://hyva-themes.github.io/magento2-react-checkout/build/)**.

i18n/cs_CZ.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Doručovací adresa, kterou jste nastavili na Amazonu, není platná. Nastavte prosím jinou adresu."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","Fakturační adresa, kterou jste zadali v Amazonu, není platná pro aktuální obchod, uveďte jinou adresu."
3+
"Amazon pay not available","Amazon Pay není k dispozici"

i18n/cs_CZ.json

-5
This file was deleted.

i18n/da_DK.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Den leveringsadresse, du har angivet på Amazon, er ikke gyldig. Indstil venligst en anden adresse."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","Den indtastede fakturaadresse hos Amazon er ikke gyldig for den pågældende butik. Angiv venligst en anden adresse."
3+
"Amazon pay not available","Amazon Pay ikke tilgængelig"

i18n/da_DK.json

-5
This file was deleted.

i18n/de_DE.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Die von Ihnen bei Amazon eingestellte Lieferadresse ist nicht gültig. Bitte legen Sie eine andere Adresse fest."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","Die von Ihnen bei Amazon eingestellte Rechnungsadresse ist für den aktuellen Shop nicht gültig, bitte legen Sie eine andere Adresse fest."
3+
"Amazon pay not available","Amazon Pay ist nicht verfügbar"

i18n/de_DE.json

-5
This file was deleted.

i18n/en_GB.json

-1
This file was deleted.

i18n/en_US.json

-1
This file was deleted.

i18n/es_ES.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","La dirección de envío que configuraste en Amazon no es válida. Establece una dirección diferente."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","La dirección de facturación que ha configurado en Amazon no es válida para la tienda actual, establezca otra dirección."
3+
"Amazon pay not available","Amazon Pay no disponible"

i18n/es_ES.json

-5
This file was deleted.

i18n/fi_FI.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Amazonissa asettamasi toimitusosoite ei ole kelvollinen. Aseta toinen osoite."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","Amazonin portaalissa määrittelemäsi laskutusosoite ei kelpaa tässä kaupassa. Määrittele jokin muu osoite."
3+
"Amazon pay not available","Amazon Pay ei käytettävissä"

i18n/fi_FI.json

-5
This file was deleted.

i18n/fr_FR.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","L'adresse de livraison que vous avez définie sur Amazon n'est pas valide. Veuillez définir une adresse différente."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","L'adresse de facturation que vous avez définie sur Amazon n'est pas valide pour le magasin actuel, veuillez définir une autre adresse."
3+
"Amazon pay not available","Amazon Pay n'est pas disponible"

i18n/fr_FR.json

-5
This file was deleted.

i18n/hr_HR.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Adresa za dostavu koju ste postavili na Amazonu nije važeća. Postavite drugu adresu."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","Adresa za naplatu koju ste postavili za Amazon nije važeća za trenutačnu trgovinu, postavite drugu adresu."
3+
"Amazon pay not available","Amazon Pay nije raspoloživ"

i18n/hr_HR.json

-5
This file was deleted.

i18n/it_IT.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","L'indirizzo di spedizione che hai impostato su Amazon non è valido. Imposta un indirizzo diverso."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","L'indirizzo di fatturazione che hai impostato su Amazon non è valido per il negozio attuale, imposta un altro indirizzo."
3+
"Amazon pay not available","Amazon Pay non disponibile"

i18n/it_IT.json

-5
This file was deleted.

i18n/nl_NL.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Het verzendadres dat je op Amazon hebt ingesteld, is niet geldig. Stel een ander adres in."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address.","Het factuuradres dat je hebt ingesteld op Amazon is niet geldig voor de huidige winkel, stel een ander adres in."
3+
"Amazon pay not available","Amazon Pay niet beschikbaar"

i18n/nl_NL.json

-5
This file was deleted.

i18n/pl_PL.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Adres wysyłki ustawiony na Amazon jest nieprawidłowy. Ustaw inny adres."
2+
"The billing address you have set on Amazon is not valid for the current store, please set another address","Wybrany w Amazonie adres rozliczeniowy jest niedozwolony dla tego sklepu. Należy ustalić inny adres."
3+
"Amazon pay not available","Amazon Pay niedostępny"

i18n/pl_PL.json

-5
This file was deleted.

i18n/tr_TR.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"The billing address you have set on Amazon is not valid for the current store, please set another address","Amazon'da kayıtlı bulunan fatura adresiniz bu site için geçerli değildir. Lütfen başka bir adres kaydedin."
2+
"The shipping address you have set on Amazon is not valid for the current store, please set another address","Amazon'da belirlediğiniz teslimat adresi geçerli değil. Lütfen farklı bir adres belirleyin."
3+
"Amazon pay not available","Amazon Pay kullanılamaz"

i18n/tr_TR.json

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import restGetCheckoutSessionButtonPayload from './restCheckoutSessionButtonPayload';
2+
3+
export default restGetCheckoutSessionButtonPayload;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { _isObjEmpty } from '../../../../../utils';
2+
3+
export default function restGetCheckoutSessionButtonPayloadModifier(result) {
4+
let initCheckoutPayload = {};
5+
6+
if (!_isObjEmpty(result)) {
7+
initCheckoutPayload = {
8+
createCheckoutSessionConfig: {
9+
payloadJSON: result[0],
10+
signature: result[1],
11+
},
12+
};
13+
}
14+
15+
return initCheckoutPayload;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import modifier from './modifier';
2+
import RootElement from '../../../../../utils/rootElement';
3+
import sendRequest, { RESPONSE_JSON } from '../../../../../api/sendRequest';
4+
5+
export default async function restGetCheckoutSessionButtonPayload(
6+
appDispatch,
7+
payloadType
8+
) {
9+
const paymentConfig = RootElement.getPaymentConfig();
10+
const url = `${paymentConfig.restUrlPrefix}amazon-checkout-session/button-payload/${payloadType}`;
11+
12+
return modifier(
13+
await sendRequest(appDispatch, {}, url, RESPONSE_JSON, {}, true)
14+
);
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { _isObjEmpty } from '../../../../../utils';
22

3-
export default function restGetCheckoutSessionConfig(result) {
3+
export default function restGetCheckoutSessionConfigModifier(result) {
44
if (!_isObjEmpty(result)) {
55
const sessionConfig = result[0] || {};
6+
67
return {
8+
productType: false,
9+
sandbox: sessionConfig.sandbox,
710
merchantId: sessionConfig.merchant_id,
811
ledgerCurrency: sessionConfig.currency,
912
buttonColor: sessionConfig.button_color,
1013
checkoutLanguage: sessionConfig.language,
11-
productType: false,
12-
sandbox: sessionConfig.sandbox,
14+
publicKeyId: sessionConfig.public_key_id,
1315
loginPayload: sessionConfig.login_payload,
1416
loginSignature: sessionConfig.login_signature,
15-
checkoutReviewPayload: sessionConfig.checkout_payload,
16-
checkoutReviewSignature: sessionConfig.checkout_signature,
1717
checkoutPayload: sessionConfig.paynow_payload,
1818
checkoutSignature: sessionConfig.paynow_signature,
19-
publicKeyId: sessionConfig.public_key_id,
19+
checkoutReviewPayload: sessionConfig.checkout_payload,
20+
checkoutReviewSignature: sessionConfig.checkout_signature,
2021
};
2122
}
23+
2224
return {};
2325
}

src/components/AmazonPay.jsx

+13-97
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,18 @@
1-
import { func, shape, string } from 'prop-types';
2-
import React, { useCallback, useEffect } from 'react';
3-
import _get from 'lodash.get';
4-
import RadioInput from '../../../../components/common/Form/RadioInput';
5-
import useAmazonPay from '../hooks/useAmazonPay';
6-
import useAmazonPayCheckoutFormContext from '../hooks/useAmazonPayCheckoutFormContext';
7-
import useAmazonPayCartContext from '../hooks/useAmazonPayCartContext';
8-
import useAmazonPayAppContext from '../hooks/useAmazonPayAppContext';
9-
10-
function AmazonPay({ method, selected, actions }) {
11-
const methodCode = _get(method, 'code');
12-
const {
13-
getCheckoutSessionConfig,
14-
placeAmazonPayOrder,
15-
processPaymentEnable,
16-
setAddresses,
17-
} = useAmazonPay(methodCode);
18-
const { setPaymentMethod, selectedPaymentMethod } = useAmazonPayCartContext();
19-
const { setPageLoader } = useAmazonPayAppContext();
20-
const isSelected = methodCode === selected.code;
21-
const { registerPaymentAction } = useAmazonPayCheckoutFormContext();
22-
23-
const initalizeAmazonPaymentOnSelection = useCallback(async () => {
24-
setPageLoader(true);
25-
await getCheckoutSessionConfig();
26-
if (selectedPaymentMethod.code !== methodCode) {
27-
await setPaymentMethod(methodCode);
28-
}
29-
setPageLoader(false);
30-
}, [
31-
setPageLoader,
32-
getCheckoutSessionConfig,
33-
selectedPaymentMethod,
34-
methodCode,
35-
setPaymentMethod,
36-
]);
37-
38-
useEffect(() => {
39-
if (isSelected) {
40-
initalizeAmazonPaymentOnSelection();
41-
}
42-
}, [isSelected, initalizeAmazonPaymentOnSelection]);
43-
44-
useEffect(() => {
45-
if (processPaymentEnable) {
46-
setAddresses();
47-
registerPaymentAction(methodCode, placeAmazonPayOrder);
48-
}
49-
}, [
50-
setAddresses,
51-
processPaymentEnable,
52-
methodCode,
53-
registerPaymentAction,
54-
placeAmazonPayOrder,
55-
]);
56-
57-
if (isSelected) {
58-
return (
59-
<>
60-
<RadioInput
61-
label={method.title}
62-
name="paymentMethod"
63-
value={method.code}
64-
onChange={actions.change}
65-
checked={isSelected}
66-
/>
67-
<div id="AmazonPayButton" />
68-
</>
69-
);
1+
import React from 'react';
2+
3+
import AmazonPayRenderer from './AmazonPayRenderer';
4+
import config from '../utils/config';
5+
import storage from '../utils/storage';
6+
7+
function AmazonPay(props) {
8+
if (
9+
config.hasRestrictedProducts ||
10+
(!storage.isAmazonCheckout() && !config.isMethodAvailable)
11+
) {
12+
return null;
7013
}
7114

72-
return (
73-
<div className="w-full">
74-
<div>
75-
<RadioInput
76-
label={_get(method, 'title')}
77-
name="paymentMethod"
78-
value={_get(method, 'code')}
79-
onChange={actions.change}
80-
checked={isSelected}
81-
/>
82-
</div>
83-
</div>
84-
);
15+
return <AmazonPayRenderer {...props} />;
8516
}
8617

87-
const methodShape = shape({
88-
title: string,
89-
code: string.isRequired,
90-
});
91-
92-
AmazonPay.propTypes = {
93-
method: methodShape.isRequired,
94-
selected: methodShape.isRequired,
95-
actions: shape({ change: func }),
96-
};
97-
98-
AmazonPay.defaultProps = {
99-
actions: {},
100-
};
101-
10218
export default AmazonPay;

0 commit comments

Comments
 (0)