Skip to content

Commit

Permalink
feat: self serve url in env (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Jun 7, 2024
1 parent 6b4fbb7 commit 107e914
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions Hyperswitch-React-Demo-App/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ HYPERSWITCH_PUBLISHABLE_KEY=
HYPERSWITCH_SECRET_KEY=
HYPERSWITCH_SERVER_URL=
HYPERSWITCH_CLIENT_URL=
SELF_SERVER_URL=

8 changes: 5 additions & 3 deletions Hyperswitch-React-Demo-App/src/Payment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
import { useEffect, useState } from "react";
import React from "react";
import { HyperElements } from "@juspay-tech/react-hyper-js";
Expand All @@ -8,10 +9,11 @@ function Payment() {
const [clientSecret, setClientSecret] = useState("");

useEffect(() => {
let url = SELF_SERVER_URL === "" ? ENDPOINT : SELF_SERVER_URL;
Promise.all([
fetch(`${endPoint}/config`),
fetch(`${endPoint}/urls`),
fetch(`${endPoint}/create-payment-intent`),
fetch(`${url}/config`),
fetch(`${url}/urls`),
fetch(`${url}/create-payment-intent`),
])
.then((responses) => {
return Promise.all(responses.map((response) => response.json()));
Expand Down
6 changes: 2 additions & 4 deletions Hyperswitch-React-Demo-App/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ module.exports = (endpoint, publicPath = "auto") => {
template: "./public/playgroundIndex.html",
}),
new webpack.DefinePlugin({
endPoint:
typeof endpoint === "string"
? JSON.stringify(endpoint)
: JSON.stringify(process.env.SELF_SERVER_URL),
ENDPOINT: JSON.stringify(endpoint),
SCRIPT_SRC: JSON.stringify(process.env.HYPERSWITCH_CLIENT_URL),
SELF_SERVER_URL: JSON.stringify(process.env.SELF_SERVER_URL ?? ""),
}),
new BundleAnalyzerPlugin({
analyzerMode: "static",
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Before you start the local setup, you will need an understanding of few keys -

- **`HYPERSWITCH_CLIENT_URL`:** The URL of your hosted Hyperswitch SDK. You can also use our Sandbox URL (https://beta.hyperswitch.io/v1) or specify your app running locally (e.g., http://localhost:9050).

- **`SELF_SERVER_URL`:** The URL of the hosted server file for generating client-secret and for fetching urls & configs. (eg: http://localhost:9060/payments)

### About Env Configs for SDK

- **`ENV_BACKEND_URL`:** Sets the endpoint for all the APIs used within the SDK to interact with the backend service. If you are running your own backend service, you can configure and specify its endpoint here for local setups.
Expand Down

0 comments on commit 107e914

Please sign in to comment.