Skip to content

Commit f3a1429

Browse files
committed
Merge branch 'master' into main
2 parents 2b772bd + 6240698 commit f3a1429

File tree

15 files changed

+382
-2
lines changed

15 files changed

+382
-2
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
1-
# magento2-hyva-checkout-paypal-express
2-
Paypal Express Payment method for Hyvä Checkout
1+
# Hyvä Themes - Hyvä Checkout Paypal Express
2+
3+
[![Hyvä Themes](https://repository-images.githubusercontent.com/303806175/a3973c80-479c-11eb-8716-03e369d87143)](https://hyva.io/)
4+
5+
## hyva-themes/magento2-hyva-checkout-paypal-express
6+
7+
Paypal express payment method for Hyvä Checkout
8+
9+
## Prerequisites
10+
11+
1. **[Hyvä Checkout](https://github.com/hyva-themes/magento2-hyva-checkout)** is installed and setup.
12+
2. Paypal express is configured in the Magento 2 store backend under `Stores > Configuration > Sales > Payment Methods > Paypal Express Checkout`.
13+
14+
## How to use it with Hyvä Checkout?
15+
Add below code in your `package.json`.
16+
17+
File: `src/reactapp/package.json`
18+
19+
```
20+
"config": {
21+
"paymentMethodsRepo": {
22+
"paypalExpress": "[email protected]:hyva-themes/magento2-hyva-checkout-paypal-express.git"
23+
}
24+
},
25+
```
26+
With this code in `package.json` and running `npm install`, then you are all set. This repo will be copied into the Hyvä Checkout and configured correctly.
27+
28+
Finally, we need to build the app again. For this, you need to run `npm run build` from the root directory of Hyvä Checkout react app (`src/reactapp`). After this, if you navigate to the checkout page from your site, then you will see the paypal express payment option you have configured in the above step.
29+
30+
## More Reading
31+
32+
- If you have any doubts about the building the react app, then **[read more about it here](https://hyva-themes.github.io/magento2-hyva-checkout/build/)**.
33+
- If you want to know more about how Hyvä Checkout helps you to integrate any payment methods, then **[read more about it here](https://hyva-themes.github.io/magento2-hyva-checkout/payment-integration/)**.
34+
- The official documentation of **[Hyvä Checkout](https://hyva-themes.github.io/magento2-hyva-checkout)**
35+
- The Magento documentation of **[Paypal Express](https://docs.magento.com/user-guide/payment/paypal-express-checkout.html)**

i18n/en_US.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Something went wrong while adding the payment method to the quote.": "Something went wrong while adding the payment method to the quote.",
3+
"Please complete all the required data.": "Please complete all the required data.",
4+
"Paypal Error": "Paypal Error"
5+
}

renderers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import PaypalExpress from './src/components/PaypalExpress';
2+
3+
export default {
4+
paypal_express: PaypalExpress,
5+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { CREATE_PAYPAL_EXPRESS_TOKEN } from './mutation';
2+
import sendRequest from '../../../../../api/sendRequest';
3+
import LocalStorage from '../../../../../utils/localStorage';
4+
import modifier from './modifier';
5+
6+
export default async function createCustomerToken(createTokenInput) {
7+
const variables = { ...createTokenInput, cartId: LocalStorage.getCartId() };
8+
9+
return modifier(
10+
await sendRequest({ query: CREATE_PAYPAL_EXPRESS_TOKEN, variables })
11+
);
12+
}

src/api/createCustomerToken/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import createPaypalExpressCustomerToken from './createCustomerToken';
2+
3+
export default createPaypalExpressCustomerToken;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import _get from 'lodash.get';
2+
3+
export default function createCustomerTokenModifier(result) {
4+
return _get(result, 'data', {});
5+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const CREATE_PAYPAL_EXPRESS_TOKEN = `
2+
mutation createPaypalExpressToken(
3+
$cartId: String!
4+
$returnUrl: String!
5+
$cancelUrl: String!
6+
$paymentCode: String!
7+
) {
8+
createPaypalExpressToken(
9+
input: {
10+
cart_id: $cartId
11+
code: $paymentCode
12+
express_button: true
13+
urls: {
14+
return_url: $returnUrl,
15+
cancel_url: $cancelUrl
16+
}
17+
}
18+
) {
19+
token
20+
paypal_urls {
21+
start
22+
edit
23+
}
24+
}
25+
}
26+
`;

src/api/setPaymentMethod/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import setPaypalExpressPaymentMethod from './setPaymentMethod';
2+
3+
export default setPaypalExpressPaymentMethod;

src/api/setPaymentMethod/modifier.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import _get from 'lodash.get';
2+
3+
export default function createCustomerTokenModifier(result) {
4+
return _get(result, 'data', {});
5+
}

src/api/setPaymentMethod/mutation.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const SET_PAYMENT_METHOD_ON_CART_PAYPAL_EXPRESS = `
2+
mutation setPaymentMethodOnCart(
3+
$payerId: String!
4+
$token: String!
5+
$cartId: String!
6+
$paymentCode: String!
7+
) {
8+
setPaymentMethodOnCart(
9+
input: {
10+
cart_id: $cartId,
11+
payment_method: {
12+
code: $paymentCode
13+
paypal_express: {
14+
payer_id: $payerId
15+
token: $token
16+
}
17+
}
18+
}
19+
) {
20+
cart {
21+
selected_payment_method {
22+
code
23+
title
24+
}
25+
}
26+
}
27+
}
28+
`;

0 commit comments

Comments
 (0)