Status API Full Implementation Example

Below is a full example usage of the Status API implementation in the retailer's checkout.

Let's do an example of a checkout process that has been completed thought the SDK. (If you are not familiar with the SDK events, please see SDK Events).

Inside this SDK's callback functions, the retailer must call a new service hosted on the retailer's side. From this service, (on the server side), the Status API must be called with the provided token and application id to ensure that the application is valid and the loan has been created successfully.

We will show below an example of how can this be implemented. For the process to be completely secure, 3 parts must be involved:

  • Client (Browser)
  • Server (Service acting as a middleware)
  • Server (Communicated with the retailers Database)

The client must only update the retailer's database if it has gone though the new Service. The request to the Status API must be done from this Service to prevent the retailer endpoints from being exposed to the client.

Client

Below it will show how the client should call the Service. To see the full client side implementation, please check SDK Implementation Example.

Lets assume that the new service will be running in https://my-service. Please, change this url with your own.

In the example, only the onSuccess() callback has been implemented, but the same schema can be applied to all the others.

Service

This service will be called from the client and will call the Snap Staus API to check if the status of the application matches the one that the client is sending. We have created a simple Node.js example application to show what should be done in this service.

In the example, only the /success route has been implemented, but the same Schema can be applied to all the others.

Please see Status API to see the full Status Code List, under the "Codes and states" section.

For production integration, replace base url with: https://app.snapfinance.co.uk