Prepare purchase link

purchase

Purchase

API provides the following purchase endpoints.

Purchase Subscription

To purchase subscription use the below endpoint, the endpoint can be accessed with client access token or a user access token, if the endpoint is accessed with a client access token then at the end of the purchase flow the response includes a (query) parameter "code=" which is an authorization code that can be used to obtain the user token. Please see the Get User Token section for more details

CURL example

curl --location --request POST 'https://gateway.mondiapay.com/v1/api/purchase/subscription/prepare'\

--header 'Accept: application/json' \

--header 'Content-Type: application/json' \

--header 'Authorization: Bearer C12345' \

--data-raw '{

       "redirect": "http://google.com"

       "subscriptionTypeId": 12345

}'

Or you can add the marketing details in the request to be sent back with the notifications.

CURL example

curl --location --request POST 'https://gateway.mondiapay.com/v1/api/purchase/subscription/prepare'\

--header 'Accept: application/json' \

--header 'Content-Type: application/json' \

--header 'Authorization: Bearer C12345' \

--data-raw '{

'{"marketingCampaign":{ "conversionId": "12345", "agency": "na", "medium": "na", "name": "na", "source": "na"}, "redirect": " http://google.com", "subscriptionTypeId": "12345"}', }'

Note

Marketing details may not be sent back with the notifications due to user behaviour, especially when the consent page is managed by the operator.

Response Example

{

" purchaseToken ": " 8adca8fb-4d50-42da-b069-b4da75fe8555 "

" expiresIn ": " 300 "

" _links ": " {
     "initiatePurchase": {
         "href": 'http://mondiapay-gateway.mondiamedia.com/v1/web/purchase/initiate/8adca8fb-4d50-42da-b069-b4da75fe8555
      }"
} "

}

Authorization Code

After user click on the purchase link he will be redirected back to (Redirect link after subscription - EX.Thank you page URL) with an authorization code ex. http//redirected-url.com?code=A8f01-4809-9ffd-383f2b855bf4

Generate user access token from authorization code

Once there is an authorization code which is usually available as query parameter after the purchse flow is completed, then use the following operation to get the user access token. This operation is server to server API call, it is expected that the client call this operation from their backend.

CURL example

curl --location --request POST 'https://gateway.mondiapay.com/v1/api/oauth/token?grant_type=authorization_code&client_id=12345&client_secret=12345&code=A12345&redirect_uri=https://www.google.com'\

--header 'Accept: application/json' \

--header 'Content-Type: application/x-www-form-urlencoded'

Response Example

{

" access_token ": " U8e8f025e-8f01-4809-9ffd-383f2b855bf4 "

" token_type ": " bearer "

" expires_in ": " 43200 "

" refresh_token ": " R8e8f025e-8f01-4809-9ffd-383f2b855bf4 "

}

Use the User Access Token to get the subscription details:

CURL example

curl --location --request GET ''https://gateway.mondiapay.com/v1/api/subscription?subscriptionTypeId=12345'\

--header 'Authorization: Bearer U12345'

Response Example

{

" typeId ": " 12345 "

" startDate ": " 2021-01-16T19:45:01Zer "

" id ": " 12345 "

" created ": " 2021-01-16T19:45:01Z "

" lastModified ": " 2021-01-16T19:45:01Z "

" attributes ": " [] "

" state ": " ACTIVE "

" subState ": " NONE "

}