Sample code for 30+ languages & platforms
Visual Basic 6.0 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 Visual Basic 6.0 Downloads

Visual Basic 6.0
'  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New ChilkatHttp
http.RequireSslCertVerify = 1

http.SetRequestHeader "Authorization","CHAT_2_PAY_API_KEY"
http.SetRequestHeader "Accept","application/json"
Dim now As New CkDateTime
success = now.SetFromCurrentSystemTime()
Dim orderNumber As String
orderNumber = "ORD-1042"
Dim body As New ChilkatJsonObject
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")
Dim resp As New ChilkatHttpResponse
Dim sent As Long
sent = http.HttpJson("POST","https://chat2pay-service.clickatell.com/api/v2/chat-2-pay",body,"application/json",resp)
If (resp.StatusCode = 0) Then
    Debug.Print "No HTTP response. Check this order in Chat 2 Pay before retrying."
    Exit Sub
End If

Dim reply As New ChilkatJsonObject
Dim parsed As Long
parsed = reply.Load(resp.BodyStr)
If ((sent <> 1) Or (resp.StatusCode <> 201)) Then
    Debug.Print "Payment-link request returned HTTP " & resp.StatusCode
    If (reply.HasMember("message") = 1) Then
        Debug.Print reply.StringOf("message")
    End If

    Exit Sub
End If

Dim reference As String
reference = reply.StringOf("paymentLinkRef")
If ((parsed <> 1) Or (reply.JsonTypeOf("paymentLinkRef") <> 1) Or (reference = "")) Then
    Debug.Print "Missing payment link reference. Check the transaction before retrying."
    Exit Sub
End If

Dim record As New ChilkatJsonObject
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

Dim saved As Long
saved = record.WriteFile("order-1042-payment-link.json")
If (saved <> 1) Then
    Debug.Print "Link already created. Save this reference with the order: " & reference
    Exit Sub
End If

Debug.Print "Saved the payment link reference for " & orderNumber