Lua Requires Chilkat v11.0.0+
Lua
CardConnect Create Profile
See more CardConnect Examples
Demonstrates how to create a profile.A PUT call to the profile endpoint creates a new profile or adds a new account to an existing profile. ...
See https://developer.cardconnect.com/cardconnect-api?lang=json#create-update-profile-request
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
http.basic_auth = true
http.login = "API_USERNAME"
http.password = "API_PASSWORD"
-- Build and send the following JSON:
-- {
-- "region": "AK",
-- "phone": "7778789999",
-- "accttype": "VISA",
-- "postal": "19090",
-- "ssnl4": "3655",
-- "expiry": "0214",
-- "city": "ANYTOWN",
-- "country": "US",
-- "address": "123 MAIN STREET",
-- "merchid": "496400000840",
-- "name": "TOM JONES",
-- "account": "4444333322221111",
-- "license": "123451254",
-- }
local json = chilkat.JsonObject.new()
json:update_string("region", "AK")
json:update_string("phone", "7778789999")
json:update_string("accttype", "VISA")
json:update_string("postal", "19090")
json:update_string("ssnl4", "3655")
json:update_string("expiry", "0214")
json:update_string("city", "ANYTOWN")
json:update_string("country", "US")
json:update_string("address", "123 MAIN STREET")
json:update_string("merchid", "MERCHANT_ID")
json:update_string("name", "TOM JONES")
json:update_string("account", "4444333322221111")
json:update_string("license", "123451254")
local url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/profile"
local resp = chilkat.HttpResponse.new()
local success = http:http_str("PUT", url, json:emit(), "utf-8", "application/json", resp)
if not success then
print(http.last_error_text)
return
end
-- A response status of 200 indicates potential success. The JSON response body
-- must be examined to determine if it was truly successful or an error.
print("response status code = " .. resp.status_code)
local jsonResp = chilkat.JsonObject.new()
jsonResp:load(resp.body_str)
jsonResp.emit_compact = false
print("response JSON:")
print(jsonResp:emit())
-- A successful response looks like this:
-- {
-- "country": "US",
-- "address": "123 MAIN STREET",
-- "resptext": "Profile Saved",
-- "city": "ANYTOWN",
-- "acctid": "1",
-- "respcode": "09",
-- "defaultacct": "Y",
-- "accttype": "VISA",
-- "token": "9441149619831111",
-- "license": "123451254",
-- "respproc": "PPS",
-- "phone": "7778789999",
-- "profileid": "16392957457306633141",
-- "name": "TOM JONES",
-- "auoptout": "N",
-- "postal": "19090",
-- "expiry": "0214",
-- "region": "AK",
-- "ssnl4": "3655",
-- "respstat": "A"
-- }
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
local country = jsonResp:string_of("country")
local address = jsonResp:string_of("address")
local resptext = jsonResp:string_of("resptext")
local city = jsonResp:string_of("city")
local acctid = jsonResp:string_of("acctid")
local respcode = jsonResp:string_of("respcode")
local defaultacct = jsonResp:string_of("defaultacct")
local accttype = jsonResp:string_of("accttype")
local token = jsonResp:string_of("token")
local license = jsonResp:string_of("license")
local respproc = jsonResp:string_of("respproc")
local phone = jsonResp:string_of("phone")
local profileid = jsonResp:string_of("profileid")
local name = jsonResp:string_of("name")
local auoptout = jsonResp:string_of("auoptout")
local postal = jsonResp:string_of("postal")
local expiry = jsonResp:string_of("expiry")
local region = jsonResp:string_of("region")
local ssnl4 = jsonResp:string_of("ssnl4")
local respstat = jsonResp:string_of("respstat")