Skip to content

Payment integration between Stripe Payments Gateway and the Resellerclub Supersite platform.

License

Notifications You must be signed in to change notification settings

JamesShaver/stripepayments

Repository files navigation

Resellerclub and Stripe Gateway Integration with Cloudflare Workers

This repository demonstrates how to integrate Stripe Payments with Cloudflare Workers using KV storage for securely managing keys, and submitting transactions to Resellerclub. It includes both the front-end (payment form with Stripe Elements) and back-end logic (payment intent creation, checksum generation, and form submission).

Features

  • Stripe Payment Integration: Accept payments securely using Stripe's Payment Elements.
  • Checksum Validation: Secure your transactions by generating and validating checksums using MD5 hashing.
  • Cloudflare Workers: Serverless backend to handle payments and checksum generation.
  • Resellerclub Integration: Submit payment data to Resellerclub with the required parameters after confirming payment.

Getting Started

1. Fork the Repository

  1. Fork this repository to your GitHub account.

  2. Clone the repository to your local machine: git clone https://github.com/JamesShaver/stripepayments.git cd stripepayments

2. Set Up Cloudflare Workers

  1. Install the Cloudflare CLI tool wrangler: npm install -g wrangler

  2. Authenticate wrangler with your Cloudflare account: wrangler login

  3. Create a new Worker project if you don't have one already: wrangler init

  4. Modify the wrangler.toml file to match your Cloudflare Worker project settings. Here's an example:

name = "stripe-cloudflare-worker"
type = "javascript"
account_id = "your-cloudflare-account-id"
workers_dev = true
kv_namespaces = [
  { 
    binding = "KV", id = "your-kv-namespace-id" 
  }
]
  1. Add the necessary KV storage entries to your Cloudflare KV namespace. These entries will be used for securely storing Stripe API keys and your payment gateway key:

wrangler kv:key put --binding=KV STRIPE_TEST_PUBLIC "your-stripe-public-key"
wrangler kv:key put --binding=KV STRIPE_TEST_SECRET "your-stripe-secret-key"
wrangler kv:key put --binding=KV RC_PAYMENT_GATEWAY_KEY "your-resellerclub-payment-gateway-key"

3. Deploy the Cloudflare Worker

Once you've configured the KV storage and set up your wrangler.toml, you can deploy the worker:

wrangler publish

This will deploy your Worker to Cloudflare. Make sure to copy the deployed URL, as you will use it in the next steps.

4. Test Integration with Resellerclub

You can now test the payment flow in Resellerclub by integrating your Worker into the Resellerclub platform.

1. Set up in Resellerclub

  • Log in to your Resellerclub account and go to the Payment Gateway Integration section.
  • Enter the following details and save your changes by clicking Submit:
  • Add your Cloudflare Worker URL as the endpoint for handling payments.
    • Gateway Name: This is the heading for your Payment Gateway and it will be displayed to your Customers / Sub-Resellers on the Payment page within a dropdown of options. You could add for example "Stripe Payments", or "VISA/MasterCard/AMEX" in order to signify that your Customer / Sub-Reseller can pay using those modes if they select this particular option.
    • Gateway URL: This is the URL on your Cloudflare Worker to which we will redirect the Customer / Sub-Reseller. This is explained in detail further ahead. Currently, simply fill in some URL. We will change this later to the correct URL.
    • Payment Gateway Access Level for Customers / Sub-Resellers: Select appropriate Access Levels for your Customers / Sub-Resellers. Custom Payment Settings

2. Test Payment Flow

Once the integration is set up in Resellerclub:

  • Perform a test transaction by making a payment.
  • The transaction will redirect to the Worker, where the payment is processed via Stripe.
  • After the payment is confirmed, the Worker will generate the checksum and redirect the user back to Resellerclub.

5. Local Development

To test your Cloudflare Worker locally, you can use wrangler's development mode: wrangler dev

This will run your Worker locally on http://127.0.0.1:8787 and allow you to test it before deploying, though you should expect the checksum to fail as it's not going through Resellerclub.

6. (Optional) Setup a subdomain pointing to your worker

Custom Domains can be attached to your Worker via the Cloudflare dashboard, Wrangler or the API.

A CNAME (Canonical Name) record is used to create an alias for a domain name. It essentially points a subdomain to another domain or subdomain. While this step is optional, it does provide peace of mind to your customers that your payment platform is reputable.

Set up a Custom Domain in the dashboard

To set up a Custom Domain in the dashboard:

  1. Log in to the Cloudflare dashboard and select your account.
  2. Select Workers & Pages and in Overview, select your Worker.
  3. Go to Settings > Triggers > Custom Domains > Add Custom Domain.
  4. Enter the domain you want to configure for your Worker.
  5. Select Add Custom Domain.

After you have added the domain or subdomain, Cloudflare will create a new DNS record for you. You can add multiple Custom Domains.

Set up a Custom Domain in your wrangler.toml

To configure a Custom Domain in your wrangler.toml, add the custom_domain=true option on each pattern under routes. For example, to configure a Custom Domain:

routes = [
  { pattern = "shop.example.com", custom_domain = true }
]

To configure multiple Custom Domains:

routes = [
  { pattern = "shop.example.com", custom_domain = true },
  { pattern = "shop-two.example.com", custom_domain = true }
]

Configuration

Make sure the following environment variables are correctly set in KV Storage:

  • STRIPE_TEST_PUBLIC: Your Stripe public key.
  • STRIPE_TEST_SECRET: Your Stripe secret key.
  • RC_PAYMENT_GATEWAY_KEY: The Resellerclub payment gateway key.

Troubleshooting

Common Issues

  • Invalid Checksum: If you're encountering an invalid checksum error, make sure the checksum generated by Resellerclub matches the expected checksum in your Worker. The MD5 hash must include the correct values in the correct order.
  • Payment Failures: If the payment fails in Stripe, ensure your Stripe API keys are correct and that your Stripe account is in test mode if you are testing.

Debugging

  • Use wrangler dev for local testing and debugging.
  • Use the Cloudflare dashboard's Worker Logs feature to view logs in real time if issues arise in production.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

Payment integration between Stripe Payments Gateway and the Resellerclub Supersite platform.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published