A lambda that retrieves a token, and uses it to create a Stitch PaymentInitiationRequest and returns the URL and ID
If you're just here to see code examples for integrating with the Stitch API. The files you'll want are:
function/stitch/retrieve-client-token.ts
-- generates a client assertion and fetches a token.function/stitch/payment-request-create.ts
-- builds the GraphQL query to generate a PaymentInitiationRequestfunction/stitch/fetch-graqhql.ts
-- simply executes the network request to the Stitch API
If you would like to implement and deploy the function, you'll need to follow the guide below.
Take a look at function/settings.ts
to see how the environment variables are loaded.
In order to run the Lambda, the following environment variables will need to be present:
STITCH_PRIVATE_KEY
-- the private key portion of the certificate issued to you by Stitch.STITCH_CLIENT_ID
-- the client ID issued to you by Stitch.
This will need to be done locally, and on the environment the lambda will be running, see: Configuring environment variables for AWS Lambdas.
If you would rather set these values using a different method, you will need to configure that behaviour in function/settings.ts
.
Install: npm run install
Build: npm run build
Curl example (replace the function URL, and beneficiary information):
curl --request POST \
--url <FUNCTION-URL> \
--header 'Content-Type: application/json' \
--data '{
"quantity": 1,
"currency": "ZAR",
"payerReference": "Test",
"beneficiaryReference": "Test",
"beneficiaryBank": "<BANK-ID>",
"beneficiaryAccountNum": "<BENEFICIARY-ACCOUNT-NUMBER>",
"beneficiaryName": "<BENEFICIARY-NAME>"
}'
Feel free to open any issues, PRs, and direct any conversation to the Stitch Slack community
This function offers no authorization. It merely serves as an example, and accepts beneficiary information via the POST body. It is strongly recommended you secure this function to avoid malicious generation of payment requests using your client information. See: Lambda authorizers