-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.1.2 -> 2.1.3 Merge changes (#1856)
* THEMES-1520: Enable testing (and linting THEMES-1460) (#1809) * THEMES-1520: Enable testing (and linting THEMES-1460) * Re-enable test on github action * try to get stylelint to ignore jsx * Attempt #2 to get stylelint to ignore jsx * ASUB-7844 PayPal block (#1806) * move stripe logic into a button * add paypal logic * clean up and try adding styles * clean up logic and create hooks * update styles for paypal * address feedback * add more strings for intl * address feedback * address feedback * add test for PayPal block --------- Co-authored-by: Vito Galatro <[email protected]> * ASUB-7844 Fix issue where identity is not defined in paymentInfo (#1831) fix issue where identity is not defined in paymentInfo * Fix paywall Issue (#1824) * fixing ArcP.run * attending feedback * attending feedback * attending feedback * attending feedback * attending feedback * ASUB-8002 Update payment method (#1813) * changes * payments * remove env file * update payment method - stripe Intents * update payment method * fixing typo * solving conflict --------- Co-authored-by: Vito Galatro <[email protected]> * ASUB-7844 Bug fix (#1836) fix issue with redirect when user is not logged in and adjust setTimeout delay * THEMES-1589: Subs phrases added for all locales (#1837) THEMES-1589: properly added new subs phrases. * Improvement update payment method - missing message (#1839) improvement update payment method- missing message * THEMES-1600: fixed more merge conflicts. * THEMES-1600: yet more merge conflicts. --------- Co-authored-by: nschubach <[email protected]> Co-authored-by: edwardcho1231 <[email protected]> Co-authored-by: LauraPinilla <[email protected]>
- Loading branch information
1 parent
0e35554
commit 0e3d9fb
Showing
15 changed files
with
21,899 additions
and
1,224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Funtion to append additional parameters as part of URL | ||
const appendURLParams = (initURL, params) => { | ||
|
||
let fullURL = initURL; | ||
if (params.length) { | ||
const allParams = params.map((x) => Object.keys(x) + "=" + Object.values(x)).join("&"); | ||
fullURL = initURL.includes("?") ? `${initURL}&${allParams}` : `${initURL}?${allParams}`; | ||
} | ||
|
||
return fullURL; | ||
}; | ||
|
||
export default appendURLParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
import { usePaymentRedirect } from "../usePaymentRedirect"; | ||
import { usePhrases } from "@wpmedia/arc-themes-components"; | ||
|
||
export const PaypalCheckout = ({ labelOrderNumber, paypal, orderNumber, successURL }) => { | ||
const phrases = usePhrases(); | ||
const params = new URLSearchParams(window.location.search); | ||
const token = params.get("token"); | ||
|
||
// Paypal can't pass back the orderNumber to us (like other payment methods does, e.g. payment express), we store it in local storage | ||
if (orderNumber) { | ||
localStorage.setItem(labelOrderNumber, orderNumber); | ||
} else { | ||
orderNumber = localStorage[labelOrderNumber]; | ||
} | ||
|
||
const { error } = usePaymentRedirect(paypal, orderNumber, token, "parameter1", successURL); | ||
|
||
return ( | ||
<> | ||
<div data-testid="paypal-message-div">{token ? phrases.t("subscriptions-block.paypal-processing") : phrases.t("subscriptions-block.paypal-redirect-label")}</div> | ||
<div data-testid="paypal-error-message-div">{error && phrases.t("subscriptions-block.payment-error") }</div> | ||
</> | ||
); | ||
}; | ||
|
||
PaypalCheckout.displayName = "PaypalCheckout"; | ||
|
||
export default PaypalCheckout; |
22 changes: 22 additions & 0 deletions
22
blocks/subscriptions-block/components/PayPal/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import { render, screen, act } from "@testing-library/react"; | ||
|
||
import PayPal from "./index"; | ||
|
||
it("renders", async () => { | ||
await act( | ||
async () => render( | ||
<PayPal | ||
labelOrderNumber = {"ArcSubs_OrderNumber"} | ||
paypal = {{paymentMethodType: 10, paymentMethodID: 4339}} | ||
orderNumber = "XAUEWT5S4PJJTAYY" | ||
successURL = "/success" | ||
isInitialized = {false} | ||
/> | ||
) | ||
) | ||
|
||
expect(screen.getByTestId('paypal-message-div').innerHTML).toBe('subscriptions-block.paypal-redirect-label'); | ||
expect(screen.getByTestId('paypal-error-message-div')).not.toBeNull(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
blocks/subscriptions-block/components/usePaymentOptions.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
import useSales from "./useSales"; | ||
|
||
const STRIPE_PAYMENT_METHOD_ID = 18; | ||
const PAYPAL_METHOD_ID = 10; | ||
|
||
const getPaymentMethodByID = (paymentOptions, paymentMethodTypeID, paymentMethodID) => { | ||
const stripeDefault = paymentOptions?.find( | ||
(opts) => | ||
opts?.paymentMethodType === paymentMethodTypeID && opts?.paymentMethodID === paymentMethodID, | ||
); | ||
|
||
if (stripeDefault) { | ||
return stripeDefault; | ||
} else { | ||
const allStripeIntents = paymentOptions?.filter( | ||
(opts) => opts?.paymentMethodType === paymentMethodTypeID, | ||
); | ||
|
||
var minStripeIntentsID = allStripeIntents.reduce(function (res, obj) { | ||
return obj.paymentMethodID < res.paymentMethodID ? obj : res; | ||
}); | ||
return minStripeIntentsID; | ||
} | ||
}; | ||
|
||
// On subscriptions side we can setup multiple payment providers with the same typeID. | ||
// This hook is on charge to return the default one or the one with the min paymentMethodID | ||
export const usePaymentOptions = (stripeIntentsDefaultID, paypalDefaultID) => { | ||
const [paymentOpts, setPaymentOpts] = useState(); | ||
const [paypal, setPaypal] = useState(); | ||
const [stripeIntents, setStripeIntents] = useState(); | ||
const [error, setError] = useState(); | ||
|
||
const { Sales } = useSales(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const options = await Sales.getPaymentOptions(); | ||
const stripe = getPaymentMethodByID( | ||
options, | ||
STRIPE_PAYMENT_METHOD_ID, | ||
stripeIntentsDefaultID, | ||
); | ||
const paypal = getPaymentMethodByID(options, PAYPAL_METHOD_ID, paypalDefaultID); | ||
setPaymentOpts(options); | ||
setPaypal(paypal); | ||
setStripeIntents(stripe); | ||
} catch (e) { | ||
setError(e); | ||
} | ||
}; | ||
fetchData(); | ||
}, []); | ||
|
||
return { | ||
paymentOpts, | ||
stripeIntents, | ||
paypal, | ||
error | ||
}; | ||
}; | ||
|
||
export default usePaymentOptions; |
Oops, something went wrong.