Sample code for 30+ languages & platforms
VBScript Requires Chilkat v11.0.0+

Clickatell Chat 2 Pay: Send a payment link for an order

See more Clickatell Examples

Use a configured Chat 2 Pay application and its own API key. Supply the application ID, an unpaid order, and a recipient on the configured SMS channel. Clickatell creates and sends the checkout link. HTTP 201 returns a paymentLinkRef that can be saved on the order. Keep the order unpaid pending confirmation of payment.

The example writes a local reference record for the sample order. After an uncertain network result, check the transaction in Clickatell before creating another link.

Clickatell API reference

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1

http.SetRequestHeader "Authorization","CHAT_2_PAY_API_KEY"
http.SetRequestHeader "Accept","application/json"
set now = CreateObject("Chilkat.CkDateTime")
success = now.SetFromCurrentSystemTime()
orderNumber = "ORD-1042"
set body = CreateObject("Chilkat.JsonObject")
success = body.UpdateString("applicationId","CHAT_2_PAY_APPLICATION_ID")
success = body.UpdateString("channel","sms")
success = body.UpdateString("to","PHONE_NUMBER")
success = body.UpdateString("orderNumber",orderNumber)
success = body.UpdateString("timestamp",now.GetAsTimestamp(0))
success = body.UpdateString("currency","USD")
success = body.UpdateNumber("totalAmount","49.95")
set resp = CreateObject("Chilkat.HttpResponse")
sent = http.HttpJson("POST","https://chat2pay-service.clickatell.com/api/v2/chat-2-pay",body,"application/json",resp)
If (resp.StatusCode = 0) Then
    outFile.WriteLine("No HTTP response. Check this order in Chat 2 Pay before retrying.")
    WScript.Quit
End If

set reply = CreateObject("Chilkat.JsonObject")
parsed = reply.Load(resp.BodyStr)
If ((sent <> 1) Or (resp.StatusCode <> 201)) Then
    outFile.WriteLine("Payment-link request returned HTTP " & resp.StatusCode)
    If (reply.HasMember("message") = 1) Then
        outFile.WriteLine(reply.StringOf("message"))
    End If

    WScript.Quit
End If

reference = reply.StringOf("paymentLinkRef")
If ((parsed <> 1) Or (reply.JsonTypeOf("paymentLinkRef") <> 1) Or (reference = "")) Then
    outFile.WriteLine("Missing payment link reference. Check the transaction before retrying.")
    WScript.Quit
End If

set record = CreateObject("Chilkat.JsonObject")
success = record.UpdateString("orderNumber",orderNumber)
success = record.UpdateString("paymentLinkRef",reference)
If (reply.JsonTypeOf("transactionStatus") = 1) Then
    success = record.UpdateString("transactionStatus",reply.StringOf("transactionStatus"))
End If

saved = record.WriteFile("order-1042-payment-link.json")
If (saved <> 1) Then
    outFile.WriteLine("Link already created. Save this reference with the order: " & reference)
    WScript.Quit
End If

outFile.WriteLine("Saved the payment link reference for " & orderNumber)

outFile.Close