This is a quick hack from an internal Vipps hackathon. No guarantees whatsoever! We're always happy to help, but please not that this is not an officially supported Vipps solution, and we have to prioritize customers using official products. Still:Issues and PRs are welcome!
This hack is an integration between Vipps and Streamlabs.
Read about why we made this "hack" in this article on Medium
This is a Spring Boot Java application and React Express.js which integrates with the Vipps eCom v2 API and Streamlabs API.
This was useful for us:
- Vipps På Nett, which requires a company with a Norwegian organisation number. Enkeltpersonforetak is sufficient.
- Accesstoken for your Streamlabs account (not necessary to test the flow. if you don't have it now fill in a gibberish string when asked to)
-
Install Heroku CLI from https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up
-
Login to Heroku
heroku login
- Clone Server repository
git clone <repo>
- Cd into repo
cd /vipps-streamlabs
- Replace the image and name of streamer in application with your own
Replace stream-profile-picture.png
in the /frontend/public/img
directory
with your own. Height and width should be equal for best appearance.
Change text on line 143 in document frontend/src/client/home.jsx
to reflect correct streamer name.
- Cd into backend folder and init git
~/vipps-streamlabs$ cd ../backend
~/backend$ git init
- Create Heroku App for server. You need to keep the URL for the herokuapp for further steps
~/backend$ heroku create
This will return a URL for the created app back. We need this to configure our Server.
Creating <app-name>... done, stack is heroku-18
<heroku-app-url> | <heroku-git-url>
Git remote heroku added
- Create a Heroko Postgres addon
~/backend$ heroku addons:create heroku-postgresql:hobby-dev
- Cd into frontend folder and init git
~/backend$ cd ../frontend
~/frontend$ git init
- Create Heroku App for the frontend. You need to keep the URL for the herokuapp for further steps
~/frontend$ heroku create
This will return a URL for the created app back. We need this in later steps.
Creating <app-name>... done, stack is heroku-18
<heroku-app-url> | <heroku-git-url>
Git remote heroku added
- Set environment variables in
application.yaml
, which is located in/backend/src/main/resources
.
The TRANSACTION_TEXT
is what that will be shown to user when approving payment in Vipps.
STREAMLABS_ACCESS_TOKEN: Streamlabs access token
STREAMLABS_CLIENT_ID: 123
STREAMLABS_CLIENT_SECRET: 123x<t>
VIPPS_CALLBACK_PREFIX: <heroku-app-url>
VIPPS_CLIENT_ID: <Client-ID>
VIPPS_CLIENT_SECRET: <Client-Secret>
VIPPS_FALLBACK_URL: <heroku-app-url>/fallback
VIPPS_MERCHANT_SERIAL_NUMBER: <MSN>
VIPPS_OCP_APIM_SUBSCRIPTION_KEY_ACCESSTOKEN: <Sub-key>
VIPPS_OCP_APIM_SUBSCRIPTION_KEY_ECOMMERCE: <Sub-key>
TRANSACTION_TEXT: "Donasjon til Streamer"
STREAMER_NAME: "Streamer"
- Set
SERVER_URL
in frontend directory
In /frontend/src/server/routes/paymentApi.js
in line 5, change variable
SERVER_URL
to the URL for backend app.
- Deploy both apps to Heroku
Deploy Server:
~/backend$ git add .
~/backend$ git commit -m "initial commit"
~/backend$ git push heroku master
Cd into frontend
~/backend$ cd ../frontend
Deploy frontend
~/frontend$ git add .
~/frontend$ git commit -m "initial commit"
~/frontend$ git push heroku master
When both apps is deployed successfully, go to the frontend URL. From there you will be able to do donations.
In order to let people use your application and hopefully donate, you'll need to share link to the frontend application to them. You can share a link in cleartext or choose to place a button somewhere that will take the user to your application. For example in the streamer's description on Twitch.
- Upload the image that should be visible in the Twitch description to initiate Vipps donation
- Change "Bilde lenker til" to your hostname or IP address.
- Get access token:
POST:/accesstoken/get
- Initiate payment:
POST:/ecomm/v2/payments
- Listen for callback on a successful, or unsuccesful, payment in the Vipps app (
POST:[callbackPrefix]/v2/payments/{orderId}
).
Please note: This is NOT made to be a reference implementation.
We make the code available here, in case it may be useful for others. Issues and PRs are welcome!
- If a callback from Vipps API was successful, it triggered a
POST
request to the StreamlabsPOST:/donations
endpoint. The streamer then has to configure in the admin panel how the donation will be shown in the stream.
- Vipps = Vipps API
- Streamlabs = Streamlabs API
- Server = Spring Boot App
- Frontend = React Express.js App
- Streamer = Human streaming on Twitch
- User = Human watching Streamer
This is the normal view of a stream on Twitch.
The Vipps donate button is shown. Streamers are free to include whatever in their channel/stream description.
- User is watching a streamer on Twitch
- User click "Donér med Vipps"-button
Clicking the Vipps button sends the user to this page.
- User is redirected to frontend and is showed a form
- User fills in name, message to streamer and amount
- Frontend sends form data to server. Amount in USD is converted to NOK before sent to Vipps.
- Server saves the donation in a DB and initiate payment with Vipps that responds with URL that user need to approve in Vipps app
The standard Vipps landing page, where the user enters his/her phone number and confirms the donation.
- If user is on mobile, user is redirected to Vipps app to approve. If desktop, user will be redirected to a Vipps landing page first to approve it's phone number which will trigger a push notification on users phone.
The payment request in the Vipps app.
- User approve or decline payment in the Vipps app
- Vipps sends callback to server with order status (
FAILED
,SUCCESS
,CANCELLED
) - Server then update the donation in the DB.
- If order status is SUCCESS server notify Streamlabs with a POST request
The green "Betalt" bubble shows that the payment was successful.
Confirmation of the successful Vipps donation.
- User is redirected to /fallback/{orderId} in frontend
- Frontend then asks server what the status is for the donation. If server haven't recieved any callback from Vipps, it does a /getPaymentDetails request to Vipps before replying to the frontend.
- fallback page on frontend is rendered Based on
FAILED
,SUCCESS
orCANCELLED
in server response
Donation shown on the stream. Our backend received successful callback which trigger "/donations" POST-request to Streamlabs.
We're always happy to help, but please not that this is not an officially supported Vipps solution. Issues and PRs are welcome!