Quickstart
This guide will get you all set up and ready to use the trustshare API. We'll cover how to get started using one of our API clients and how to make your first API request to create a Payment Intent. We'll then look at confirming the intent we just created on the users device with the client SDK. We'll also look at where to go next to find all the information you need to take full advantage of our powerful REST API.
Before you can make requests to the API, you will need to generate your API key pair from your dashboard. You find it under Developers » API Keys.
Choose your client
Before making your first API request, you need to pick which API client you will use. In addition to good ol' cURL HTTP requests, we offer clients for JavaScript environments, as well as an Open API specification that will allow you to generate a client for your preferred language. In the following example, you can see how to install each client.
# cURL is most likely already installed on your machine
curl --version
Making your first API request
After picking your preferred client, you are ready to make your first call to the trustshare API. Below, you can see how to send a POST request to the intents endpoint to create your first Payment Intent.
curl -X POST https://rest.trustshare.io/v1/intents/payment \
-H "Authorization: <private_key>" \
-d @- << EOF
{
"type": "checkout",
"currency": "gbp",
"from": {
"email": "sink+buyer@trustshare.co"
},
"settlements": [
{
"type": "escrow",
"amount": 150000,
"description": "An example of a line item",
"to": {
"email": "sink+seller@trustshare.co"
}
}
]
}
EOF
Confirming your first intent
So far, we've already set up an API client, now we must set up the SDK
client that will allow your users to confirm their intents. Our SDK client is a
small plain JavaScript library that can be leveraged in whatever
frontend stack you are currently using. You can install the SDK via npm
...
$ >
# Install the trustshare SDK client
npm install @trustshare/sdk --save
Alternatively, If you are not using a bundler to package your application,
we also offer a CDN for including the SDK client directly in your
front-end code. In this setup, skip the above npm
install step and simply
include the client SDK directly in your page source, using one of the below snippets.
<!-- import the ESM file from CDN at the point you wish to use it -->
<script type="module">
import createSDK from 'https://unpkg.com/@trustshare/sdk/dist/index.esm.js'
</script>
On creation of the intent in the previous section, our API will return
a client_secret
which must be used by the client-device of the purchasing
Participant to confirm their intention to pay.
Depending on the overall size of the checkout, as well as your Organisation's
configuration on our system, the user will be presented
with a number of payment methods which they can choose from.
The client_secret
returned from the intent creation call should be handed directly
to the SDK on the user's device. It should not be persisted in your own system.
Confirming a payment intent
import createSDK from '@trustshare/sdk';
// The SDK is instantiated with the public key of an API key pair
const trustshare = createSDK('<public_key>');
const result = await trustshare.sdk.v1.confirmPaymentIntent('<client_secret>');
Depending on the type of the payment intent a UI may be displayed to your
buyer. Upon confirmation, the system will create a new checkout and
the SDK will resolve with a checkout_id
and project_id
.
Other reference examples
The following repositories contain examples for implementing various processes, along with native implementations for both Android and iOS.
Process examples
A collection of examples to demonstrate how to use the trustshare API.
Android integration example
An example of an Android integration with the trustshare API.
iOS integration example
An example of an iOS integration with the trustshare API.
What's next?
Great, you're now set up with an API client and have made your first payment intent on the API. Here are a few links that might be handy as you venture further into the trustshare API: