This repository offers an example of integrating Xsolla PayStation for payment processing using Maven, Java, Servlets, Tomcat, and Ngrok.
Ensure the following tools are installed on your system before proceeding:
Copy the .env.example file and rename it to .env:
cp .env.example .env
Update the .env file with the appropriate values. Your project ID is available in your Xsolla Publisher Account.
mvn clean install
The output xsolla-example.war file will be in the target directory.
It's crucial to remember that your project needs to be rebuilt whenever changes are made to the codebase or .env variables.
Run the project using Docker Compose:
docker-compose up --build
The application will be accessible at http://localhost:8080/xsolla-example/server-side.
It's crucial to remember that your Docker need to be rebuilt too after every project rebuilt.
Ngrok provides a public URL for accessing your local server. You can open the Ngrok dashboard at http://localhost:4040.
Copy the resulting URL and append /xsolla-example/webhook to it (for example, https://.ngrok-free.app/xsolla-example/webhook) and add it to the webhook settings of your project at https://publisher.xsolla.com/<YOUR_MERCHANT>/projects/<YOUR_PROJECT>/edit/webhooks/.
Create a product in your Xsolla Publisher Account. Navigate to your project > store > virtual items > add item, or open the page directly at https://publisher.xsolla.com/<YOUR_MERCHANT>/projects/<YOUR_PROJECT>/storefront/virtual-items.
Open the example UI at http://localhost:8080/xsolla-example/server-side
and modify the JSON data to get a token (set
the SKU of the project, user ID, etc.).
Payment process:
- Server: Create a token using your JSON data.
- Client: Open the payment page with your token.
- Server: Receive a webhook to validate the user.
- Client: Complete the payment.
- Server: Receive a webhook with the payment result and deliver the product to the customer.