VB.NET Requires Chilkat v11.0.0+
VB.NET
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.
Chilkat VB.NET Downloads
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.SetRequestHeader("Authorization","CHAT_2_PAY_API_KEY")
http.SetRequestHeader("Accept","application/json")
Dim now As New Chilkat.CkDateTime
now.SetFromCurrentSystemTime()
Dim orderNumber As String = "ORD-1042"
Dim body As New Chilkat.JsonObject
body.UpdateString("applicationId","CHAT_2_PAY_APPLICATION_ID")
body.UpdateString("channel","sms")
body.UpdateString("to","PHONE_NUMBER")
body.UpdateString("orderNumber",orderNumber)
body.UpdateString("timestamp",now.GetAsTimestamp(False))
body.UpdateString("currency","USD")
body.UpdateNumber("totalAmount","49.95")
Dim resp As New Chilkat.HttpResponse
Dim sent As Boolean = http.HttpJson("POST","https://chat2pay-service.clickatell.com/api/v2/chat-2-pay",body,"application/json",resp)
If (resp.StatusCode = 0) Then
Debug.WriteLine("No HTTP response. Check this order in Chat 2 Pay before retrying.")
Exit Sub
End If
Dim reply As New Chilkat.JsonObject
Dim parsed As Boolean = reply.Load(resp.BodyStr)
If ((sent <> True) Or (resp.StatusCode <> 201)) Then
Debug.WriteLine("Payment-link request returned HTTP " & resp.StatusCode)
If (reply.HasMember("message") = True) Then
Debug.WriteLine(reply.StringOf("message"))
End If
Exit Sub
End If
Dim reference As String = reply.StringOf("paymentLinkRef")
If ((parsed <> True) Or (reply.JsonTypeOf("paymentLinkRef") <> 1) Or (reference = "")) Then
Debug.WriteLine("Missing payment link reference. Check the transaction before retrying.")
Exit Sub
End If
Dim record As New Chilkat.JsonObject
record.UpdateString("orderNumber",orderNumber)
record.UpdateString("paymentLinkRef",reference)
If (reply.JsonTypeOf("transactionStatus") = 1) Then
record.UpdateString("transactionStatus",reply.StringOf("transactionStatus"))
End If
Dim saved As Boolean = record.WriteFile("order-1042-payment-link.json")
If (saved <> True) Then
Debug.WriteLine("Link already created. Save this reference with the order: " & reference)
Exit Sub
End If
Debug.WriteLine("Saved the payment link reference for " & orderNumber)