To seamlessly integrate Appcharge’s ReactJS SDK into your application, follow these steps:
- Install the SDK:
In your ReactJS app, executenpm i appcharge-checkout-reactjs-sdk
to install the Appcharge ReactJS SDK.
npm i appcharge-checkout-reactjs-sdk
- Import the SDK:
In your React component, import theAppchargeCheckout
andAppchargeCheckoutInit
components:
import { AppchargeCheckout, AppchargeCheckoutInit } from "appcharge-checkout-reactjs-sdk";
- Integrate the Component:
Note that the Appcharge's React SDK is comprised of two components,AppchargeCheckout
andAppchargeCheckoutInit
.AppchargeCheckoutInit
component needs to be rendered once - this component will create a handshake with Appcharge's Checkout solution, resulting in faster loading times for the checkout itself.AppchargeCheckout
component needs to be conditionally rendered once a user makes an action that requires payment (clicking on a bundle, for example).
Start by rendering theAppchargeCheckoutInit
component once the app loads:
<AppchargeCheckoutInit
environment="sandbox"
/>
Each time a user selects an offer in your application, performs a server-to-server request to create a checkout session, more data can be found here.
Then, incorporate Appcharge’s ReactJS Component into your code by adding the following snippet:
<AppchargeCheckout
checkoutUrl={checkoutUrl}
sessionToken={sessionToken}
referrerUrl={window.location.protocol + "//" + window.location.host}
onClose={() => console.log("Payment prompt closed")}
/>
You can show Appcharge’s ReactJS component once you have the required props by adding a state for showing and hiding the checkout component like in the following snippet:
function MyComponent() {
const [showCheckout, setShowCheckout] = useState(false);
useEffect(()=> {
// some logic to get the required props
setShowCheckout(true);
}, [])
return (
{showCheckout &&
<AppchargeCheckout
checkoutUrl={checkoutUrl}
sessionToken={sessionToken}
referrerUrl={window.location.protocol + "//" + window.location.host}
onClose={() => setShowCheckout(false)}
/>}
}
- Appcharge's checkout component allowed properties:
Prop | Type | Mandatory | Params available | Description |
---|---|---|---|---|
checkoutUrl | string | Yes | No | The checkoutUrl as provided by the "backend-to-backend" request |
sessionToken | string | Yes | No | The session token as provided by the "backend-to-backend" request |
referrerUrl | string | No | No | The domain you're coming from, for example: "www.appcharge.com" - The referrerUrl must be an HTTPS domain, |
onClose | Function | No | Yes | The checkout popup has closed |
onOrderCreated | Function | No | Yes | Order has been created |
onOrderCompletedFailed | Function | No | Yes | The order has failed due to an internal error/publisher reward error |
onOrderCompletedSuccessfully | Function | No | Yes | An order has updated with the publisher and confirmation was received |
onPaymentIntentFailed | Function | No | Yes | The player has clicked on ‘Pay’ and the payment failed |
onPaymentIntentSuccess | Function | No | Yes | The player has clicked on ‘Pay’ and the payment has been charged successfully |
All frontend events are received with a set of parameters, please notice that not all parameters are available for every event, parameters that are not available will be undefined
.
Name | Type | Description |
---|---|---|
orderId | string | Unique identifier for the order. |
date | string | Date of the order. |
sessionId | string | Identifier for the session associated with the order. |
bundleName | string | Name of the bundle associated with the order. |
bundleId | string | Identifier for the bundle. |
bundleSKU | string | Stock Keeping Unit (SKU) for the bundle. |
products | Product[] | Array of products included in the order. |
totalSum | number | Total sum of the order. |
totalSumCurrency | string | Currency of the total sum. |
paymentMethodName | string | Name of the payment method used for the order. |
userId | string | Identifier for the user placing the order. |
userCountry | string | Country associated with the user. |
reason | string | (Optional) Reason for the order or additional notes. |