Setting up API endpoints to communicate with Magic’s API.
As mentioned in the previous section, in order to make your integration secure, it is recommended to place all the communication with Magic’s API on a backend solution. It will hide your business logic and API keys from malicious activities, ensuring a more secure integration. Your backend solution should provide two endpoints to:- Obtain the checkoutId and linkToken used by Magic Link Button.
- Complete a transaction using the banking data collected in the hosted page (frontend).
Getting the checkoutId and linkToken from Magic’s API
In order to obtain the necessary parameters used by the Magic button we need to create a Checkout object by making aPOST
request to Magic API api/merchants/checkout
endpoint. If it succeeds, the response from that request will include the
checkoutId
of the newly created checkout object.
Once the checkoutId
is obtained you can get the linkToken
by making
a POST
request to Magic API
api/merchants/checkout/<checkout_id>/generate_link_token
endpoint. Make sure
to include the checkoutId
on the url.
This process can be implemented using a Django view as follows:
checkoutview.py
Use Magic API to complete a transaction
In the frontend, once all the banking data is gathered through the hosted page it is time to complete the transaction. That is implemented on theonSuccess
callback explained in the previous section. Such callback should include
a request to an endpoint in the merchant’s backend that will request Magic’s API
to complete the transaction.
This endpoint can be implemented using a Django view as follows:
completetransactionview.py