Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL loHttp
LOCAL loNow
LOCAL lcOrderNumber
LOCAL loBody
LOCAL loResp
LOCAL lnSent
LOCAL loReply
LOCAL lnParsed
LOCAL lcReference
LOCAL loRecord
LOCAL lnSaved
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
loHttp.SetRequestHeader("Authorization","CHAT_2_PAY_API_KEY")
loHttp.SetRequestHeader("Accept","application/json")
loNow = CreateObject('Chilkat.CkDateTime')
loNow.SetFromCurrentSystemTime()
lcOrderNumber = "ORD-1042"
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("applicationId","CHAT_2_PAY_APPLICATION_ID")
loBody.UpdateString("channel","sms")
loBody.UpdateString("to","PHONE_NUMBER")
loBody.UpdateString("orderNumber",lcOrderNumber)
loBody.UpdateString("timestamp",loNow.GetAsTimestamp(0))
loBody.UpdateString("currency","USD")
loBody.UpdateNumber("totalAmount","49.95")
loResp = CreateObject('Chilkat.HttpResponse')
lnSent = loHttp.HttpJson("POST","https://chat2pay-service.clickatell.com/api/v2/chat-2-pay",loBody,"application/json",loResp)
IF (loResp.StatusCode = 0) THEN
? "No HTTP response. Check this order in Chat 2 Pay before retrying."
RELEASE loHttp
RELEASE loNow
RELEASE loBody
RELEASE loResp
CANCEL
ENDIF
loReply = CreateObject('Chilkat.JsonObject')
lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSent <> 1) OR (loResp.StatusCode <> 201)) THEN
? "Payment-link request returned HTTP " + STR(loResp.StatusCode)
IF (loReply.HasMember("message") = 1) THEN
? loReply.StringOf("message")
ENDIF
RELEASE loHttp
RELEASE loNow
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
lcReference = loReply.StringOf("paymentLinkRef")
IF ((lnParsed <> 1) OR (loReply.JsonTypeOf("paymentLinkRef") <> 1) OR (lcReference = "")) THEN
? "Missing payment link reference. Check the transaction before retrying."
RELEASE loHttp
RELEASE loNow
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
loRecord = CreateObject('Chilkat.JsonObject')
loRecord.UpdateString("orderNumber",lcOrderNumber)
loRecord.UpdateString("paymentLinkRef",lcReference)
IF (loReply.JsonTypeOf("transactionStatus") = 1) THEN
loRecord.UpdateString("transactionStatus",loReply.StringOf("transactionStatus"))
ENDIF
lnSaved = loRecord.WriteFile("order-1042-payment-link.json")
IF (lnSaved <> 1) THEN
? "Link already created. Save this reference with the order: " + lcReference
RELEASE loHttp
RELEASE loNow
RELEASE loBody
RELEASE loResp
RELEASE loReply
RELEASE loRecord
CANCEL
ENDIF
? "Saved the payment link reference for " + lcOrderNumber
RELEASE loHttp
RELEASE loNow
RELEASE loBody
RELEASE loResp
RELEASE loReply
RELEASE loRecord