This repository demonstrates how to use OpenAPI to generate a TypeScript client from the Rapyd OpenAPI spec. This TS client is then used to integrate with Rapyd API.
To run this project locally, you need to have the following:
- Node.js installed on your local machine
- A Rapyd account
- Git CLI installed on your local machine
- ngrok installed on your local machine
- A code editor and a web browser
-
Obtain Rapyd API access and secret keys from Developers > API access control on the Rapyd dashboard.
-
Clone the repository.
-
Rename
.env.example
to.env
and assign provide the access and secret keys to the respective variables in the.env
file. -
Install the dependencies and seed the database using the following commands:
npm install npm run seed:products
-
Generate a TS client for Rapyd API:
npx @openapitools/openapi-generator-cli generate -i https://raw.githubusercontent.com/Rapyd-Samples/RapydOpenAPI/master/rapyd-openapi.yaml -g typescript-axios -o ./rapyd-client
-
Fix the generated client:
ts-node fix-generated-client.ts
-
Run ngrok locally, copy the forwarding URL and assign it to the
BASE_URI
variable in the.env
file:ngrok http 3000
-
Open your Rapyd dashboard, navigate to Developers > Webhooks > Management, and in the callback URL field, provide the value of the ngrok forwarding URL and append "/webhook/rapyd" to it. Under "Collect", make sure the Payment Completed event is selected so that Rapyd can send you a webhook once this event is triggered. Make sure you save the changes by clicking Save.
-
Run the server using the command
npm run dev
and open the ngrok forwarding URL on your web browser. -
Log into the application, add some items to cart, and proceed to checkout.
Check out some of our samples to learn how to build with Rapyd, and feel free to drop any questions you might have in our community.