Sample code for 30+ languages & platforms
Classic ASP 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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
'  Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1

http.SetRequestHeader "Authorization","CHAT_2_PAY_API_KEY"
http.SetRequestHeader "Accept","application/json"
set now = Server.CreateObject("Chilkat.CkDateTime")
success = now.SetFromCurrentSystemTime()
orderNumber = "ORD-1042"
set body = Server.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 = Server.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
    Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Check this order in Chat 2 Pay before retrying.") & "</pre>"
    Response.End
End If

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

    Response.End
End If

reference = reply.StringOf("paymentLinkRef")
If ((parsed <> 1) Or (reply.JsonTypeOf("paymentLinkRef") <> 1) Or (reference = "")) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Missing payment link reference. Check the transaction before retrying.") & "</pre>"
    Response.End
End If

set record = Server.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
    Response.Write "<pre>" & Server.HTMLEncode( "Link already created. Save this reference with the order: " & reference) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Saved the payment link reference for " & orderNumber) & "</pre>"

%>
</body>
</html>