Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rally to the integrations list #885

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions packages/rally/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

## Rally <sub><sup>♥</sup></sub> Next.js

To successfully integrate the Rally Checkout Button follow the steps below.
#### **1. Install the Rally Checkout Button**

```bash
npm install @rallycommerce/checkout-button
```

<br />

#### **2. Create a Rally Checkout Button component**

Create a `RallyCheckoutButton.tsx` component in the project with the following content 👇. Structure example 👉 `lib/rally/RallyCheckoutButton.tsx`

```javascript
import React from 'react'
import { Rally, RallyCheckoutButtonConfig } from '@rallycommerce/checkout-button';

declare global {
namespace JSX {
interface IntrinsicElements {
'rally-checkout-button': any;
}
}
}
interface RallyCheckoutButtonProps {
customText?: string | undefined;
customClass?: string | undefined;
cart?: any;
}

const RallyCheckoutButton = (props: RallyCheckoutButtonProps) => {
const customClass = props.customClass || "rally-custom-button-class";
const cart = props?.cart;

if (cart) {
const configuration: RallyCheckoutButtonConfig = {
cartData: { content: cart, id: cart.id, currency: cart.currency }
};

Rally.init('clientId', configuration);
}

return (<>
{<rally-checkout-button suppressHydrationWarning={true} custom-class={customClass} custom-text={props.customText} loader="true">
</rally-checkout-button>}
</>)
}

export default RallyCheckoutButton;
```

<br />

#### **3. Use the Rally Checkout Button component**

The component can now be imported (ex. on the cart page) like this 👇.

```javascript
import dynamic from 'next/dynamic';
const RallyCheckoutButton = dynamic(() => import('@lib/rally/RallyCheckoutButton'), {
ssr: false,
})

import { Context } from '../../lib/xy/storefront-data-hooks/src/Context';
const { cart } = useContext(Context)


<RallyCheckoutButton cart={cart} customText="Custom text" customClass="custom-css-class"></RallyCheckoutButton>

```

To learn more about Rally's Checkout Button capabilities visit our [Developer's portal](https://developers.rallyon.com/docs/jssdk/checkout-button/integrating-the-checkout-button/).
35 changes: 35 additions & 0 deletions packages/rally/RallyCheckoutButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import { Rally, RallyCheckoutButtonConfig } from '@rallycommerce/checkout-button';

declare global {
namespace JSX {
interface IntrinsicElements {
'rally-checkout-button': any;
}
}
}
interface RallyCheckoutButtonProps {
customText?: string | undefined;
customClass?: string | undefined;
cart?: any;
}

const RallyCheckoutButton = (props: RallyCheckoutButtonProps) => {
const customClass = props.customClass || "rally-custom-button-class";
const cart = props?.cart;

if (cart) {
const configuration: RallyCheckoutButtonConfig = {
cartData: { content: cart, id: cart.id, currency: cart.currency }
};

Rally.init('clientId', configuration);
}

return (<>
{<rally-checkout-button suppressHydrationWarning={true} custom-class={customClass} custom-text={props.customText} loader="true">
</rally-checkout-button>}
</>)
}

export default RallyCheckoutButton;