Recurring API extended Postman guide
This is a guide for the using the Recurring API with Postman, and is an extension of the Recurring API quick start guide which shows the recommended flow in both Postman and curl.
Please note: Postman is discontinuing their offline version. Use only your test keys and delete them after testing. Ensure that your company allows for cloud use before continuing.
Prerequisites
You must have already signed up as an organization with Vipps MobilePay and have your test credentials from the merchant portal, as described in the Getting started guide.
Set up
Import the following files into Postman:
The Postman collection contains examples of all the various campaign types, so it's easy to see what they look like in the app.
In Postman, tweak the environment with your own values (see API keys):
client_id- Merchant key required for getting the access token.client_secret- Merchant key required for getting the access token.Ocp-Apim-Subscription-Key- Merchant subscription key.merchantSerialNumber- Merchant ID.mobileNumber- The phone number for the test app profile you have received or registered.
You can update any of the other environment variables. Be aware of this:
- Any currency amount must be an Integer value minimum 100 in øre.
- Many URLs must be
https.
Make API calls
For all the following, you will start by sending a request Get Access Token.
This provides you with access to the API.
The access token is valid for 1 hour in the test environment and 24 hours in the production environment. See the API reference for details about the calls.
Create agreements
For details about the calls, see Agreement endpoints in the Recurring API Specifications.
Create a minimal agreement
Send request
Get Access Token. This provides you with access to the API.Set
Idempotency-Key-Draftvalue.Send the
Draft Agreement - Legacy pricingrequest. This demonstrates how to create a simple agreement usingPOST:/agreementsendpoint.Ctrl+click the link, it will take you to the landing page. Enter your test phone number and complete the authorization in the Vipps or MobilePay app in your mobile test app.
You should now have an active agreement. The variable
agreementIdis set in the environment.To get the information about an agreement, send
Get Agreement. This usesGET:/agreements/{agreementId}. The variableagreementIdis set by theDraft Agreementstep.If you confirmed the agreement, the status should be ACTIVE in the response. If you didn't go through with the confirmation, the status will be PENDING for a maximum of 10 minutes, before it goes to
EXPIRED.
Create an agreement with an initial charge
You can create more complex types of agreements by modifying the parameters in POST:/agreements endpoint.
Send
Draft Agreement - Legacy pricing and direct capture initial charge. This demonstrates the addition of an initial charge.Ctrl+click on the link and complete the authorization.
When you use this, a charge is automatically created for the initial payment and charged. The
agreementIdandchargeIdare set in the environment.Set
Idempotency-Key-Draftvalue.Send a request
Get Agreementfor information about this payment by using theGET:/agreements/{agreementId}endpoint.
Create an agreement with a reserve capture
When you use this, a charge is automatically created for the initial payment, and you can capture it when you provide the product or service.
For example, if a customer purchased a mobile phone with a data subscription, you could set up a recurring payment agreement where the price of the phone is registered as an initial payment with reserve capture. Then, you can capture the payment when you ship the phone.
Send
Draft Agreement - Legacy pricing and reserve initial charge.Ctrl+click on the link and complete the authorization.
Set
Idempotency-Key-Draftvalue.Send a request
Get Agreementfor information about this payment by using theGET:/agreements/{agreementId}endpoint.The
agreementIdandchargeIdare set in the environment. Take note of these values, because you will need them when you capture the reserved charge.
Getting access to user info
If you need to get access to some user information in addition to the recurring payment agreement, you can use the profile flow.
Send request
Draft Agreement - Profile sharing flow.Provide the
scopeobject in thePOST:/agreementscall. This contains the information types that you want access to, separated by spaces (e.g., "name address email phoneNumber birthDate").Here, the
agreementIdandlanding_page_urlare retrieved from the response and set as variables.Once you complete the session, a unique identifier
subcan be retrieved in the agreement details. Send a requestGet Agreementfor information about this payment by using theGET:/agreements/{agreementId}endpoint.In this example,
subis retrieved from the response and set as a variable.Send request
Get Userinfo, from the User Info folder. This usesGET:/vipps-userinfo-api/userinfo/{sub}with thesubvariable from the previous call.
Get a list of agreements
Send
List Agreementsto get a list of agreements by using theGET:/agreementsendpoint.This includes a query
status=ACTIVE, so it filters out other agreement states.Change or remove the query to see agreements with other states.
Update an agreement
Set
agreementIdto the ID of an ACTIVE agreement.Run
Get Agreementto see the properties of the agreement.Run
Update agreementwhich modifies some properties by using thePATCH:/agreements/{agreementId}endpoint.Run
Get Agreementto see the updated properties.
Stop an agreement
Set
agreementIdto the ID of an ACTIVE agreement.Send the
Stop agreementrequest, where the status is set toSTOPPEDin the body ofPATCH:/agreements/{agreementId}.Run
Get Agreementto see that the status is `STOPPED``.
Create charges
You will need at least one ACTIVE agreement for these examples.
For details about the calls, see Charge endpoints in the Recurring API Specifications.
Create a charge
Charges for initial payments are created automatically. However, you need to create charge requests for the recurring payments.
A charge must be scheduled a minimum of two days before the payment will occur (it is a minimum one day in the test environment). See Direct Capture for more details about timing.
Set
agreementIdto the ID of an ACTIVE agreement.Set
Idempotency-Key-Createvalue.Send
Create Charge - Direct capture. This uses thePOST:/agreements/{agreementId}/chargesendpoint.The
chargeIdvariable is set for later use.Send
Get Charge. This usesPOST:/agreements/{agreementId}/charges/{chargeId}to get information about the charge. The status will bePENDINGuntil the due date, when the payment is processed.If you run
Get Chargeagain on the due date, the status should beCHARGED.
Get a list of charges for an agreement
Set
agreementIdto the ID of an agreement. Note, you can get a list of all your agreements with theFetch Agreementsexample.Send
List Chargeswhich usesGET:/agreements/{agreementId}/charges.This includes a query
chargeStatus=DUEand filters out other charge states.Change or remove the query to see charges with other states.
Cancel a charge
You can cancel an existing charge before the user is charged.
Create a new charge, that we can safely cancel, by sending
Create Charge - Reserve capture.The
chargeIdvariable is set to this charge.Send
Cancel Chargewhich usesDEL:/agreements/{agreementId}/charges/{chargeId}.Send
Get Chargeto see the change of status.
Refund a charge
You can refund a charge that has already been charged.
Set
chargeIdto the ID of a charge with status of CHARGED. The easiest way to test this is to runDraft Agreement - Reserve initial charge. This creates a charge that is immediately processed, and it sets theagreementIdandchargeIdto the corresponding values.Set
Idempotency-Key-Refundvalue.Send
Get Chargeto see the change of status.Send
Refund Chargewhich usesPOST:/agreements/{agreementId}/charges/{chargeId}/refund.Send
Get Chargeto see that the charge is all or partially refunded. To fully refund, set theamountvalue to the amount remaining (amount-amountRefunded).
Capture reserved charge
When you create an agreement with a reserved charge, you will need to capture this charge.
In the environment, set
agreementIdandchargeIdto refer to the agreement and charge. If you ran Draft Agreement - Reserve initial charge, you can use the values set by the example.Set
Idempotency-Key-Capturevalue.Send
Get Charge, to see the status of this charge.Send
Capture reserved chargewhich usesPOST:/agreements/{agreementId}/charges/{chargeId}/capture.Send
Get Chargeagain, to see that the status is now "CHARGED".