PowerBuilder / New FreshBooks / 1. [FBPAY] - Create Payment Method
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Cc_token
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "cc_info": {
// "name": "John Johnston",
// "card_number": "4500123456789012",
// "expiry_month": "10",
// "expiry_year": "2024",
// "email": "mjohnston@freshbooks.com",
// "cvv": "123",
// "postal_code": "M6P3T1",
// "country": "CA"
// }
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("cc_info.name","John Johnston")
loo_Json.UpdateString("cc_info.card_number","4500123456789012")
loo_Json.UpdateString("cc_info.expiry_month","10")
loo_Json.UpdateString("cc_info.expiry_year","2024")
loo_Json.UpdateString("cc_info.email","mjohnston@freshbooks.com")
loo_Json.UpdateString("cc_info.cvv","123")
loo_Json.UpdateString("cc_info.postal_code","M6P3T1")
loo_Json.UpdateString("cc_info.country","CA")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Resp = loo_Http.PostJson3("https://paid.freshbooks.com/gateway/fbpay/tokenize","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "cc_token": "1122334455"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
ls_Cc_token = loo_JResp.StringOf("cc_token")
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"cc_info": {
"name": "John Johnston",
"card_number": "4500123456789012",
"expiry_month": "10",
"expiry_year": "2024",
"email": "mjohnston@freshbooks.com",
"cvv": "123",
"postal_code": "M6P3T1",
"country": "CA"
}
}'
https://paid.freshbooks.com/gateway/fbpay/tokenize
Postman Collection Item JSON
{
"name": "1. [FBPAY] - Create Payment Method",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"cc_info\": {\n \"name\": \"John Johnston\", \n \"card_number\": \"4500123456789012\", \n \"expiry_month\": \"10\", \n \"expiry_year\": \"2024\",\n \"email\": \"mjohnston@freshbooks.com\", \n \"cvv\": \"123\",\n \"postal_code\": \"M6P3T1\",\n \"country\": \"CA\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://paid.freshbooks.com/gateway/fbpay/tokenize",
"protocol": "https",
"host": [
"paid",
"freshbooks",
"com"
],
"path": [
"gateway",
"fbpay",
"tokenize"
]
}
},
"response": [
{
"name": "1. [FBPAY] - Create Payment Method",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"cc_info\": {\n \"name\": \"John Johnston\", \n \"card_number\": \"4500123456789012\", \n \"expiry_month\": \"10\", \n \"expiry_year\": \"2024\",\n \"email\": \"mjohnston@freshbooks.com\", \n \"cvv\": \"123\",\n \"postal_code\": \"M6P3T1\",\n \"country\": \"CA\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://paid.freshbooks.com/gateway/fbpay/tokenize",
"protocol": "https",
"host": [
"paid",
"freshbooks",
"com"
],
"path": [
"gateway",
"fbpay",
"tokenize"
]
}
},
"status": "CREATED",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/vnd.api+json"
},
{
"key": "Content-Length",
"value": "26"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Date",
"value": "Mon, 10 Aug 2020 18:48:08 GMT"
},
{
"key": "Server",
"value": "gunicorn/19.9.0"
},
{
"key": "Access-Control-Allow-Methods",
"value": "POST"
},
{
"key": "Access-Control-Allow-Headers",
"value": "Content-Type, X-CSRF-Token"
},
{
"key": "Access-Control-Allow-Origin",
"value": "None"
},
{
"key": "X-Version",
"value": "0.4.0"
},
{
"key": "X-FB-Backend",
"value": "U5"
},
{
"key": "Content-Security-Policy",
"value": "frame-ancestors https://*.freshbooks.com https://*.freshenv.com http://localhost:4200 https://*.billingarm.com"
},
{
"key": "X-Cache",
"value": "Miss from cloudfront"
},
{
"key": "Via",
"value": "1.1 98aedae6661e3904540676966998ed89.cloudfront.net (CloudFront)"
},
{
"key": "X-Amz-Cf-Pop",
"value": "SEA19-C2"
},
{
"key": "X-Amz-Cf-Id",
"value": "VkEJyM9NHIFX2cXfSiC6nVzflt1xmKXsN2kfTozCtT80XmkilZ-YcQ=="
}
],
"cookie": [
],
"body": "{\n \"cc_token\": \"1122334455\"\n}"
},
{
"name": "1. [FBPAY] - Create Payment Method",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"cc_info\": {\n \"name\": \"John Johnston\", \n \"card_number\": \"4500123456789012\", \n \"expiry_month\": \"10\", \n \"expiry_year\": \"2024\",\n \"email\": \"mjohnston@freshbooks.com\", \n \"cvv\": \"123\",\n \"postal_code\": \"M6P3T1\",\n \"country\": \"CA\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://paid.freshbooks.com/gateway/fbpay/tokenize",
"protocol": "https",
"host": [
"paid",
"freshbooks",
"com"
],
"path": [
"gateway",
"fbpay",
"tokenize"
]
}
},
"status": "CREATED",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/vnd.api+json"
},
{
"key": "Content-Length",
"value": "26"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Date",
"value": "Mon, 10 Aug 2020 18:48:08 GMT"
},
{
"key": "Server",
"value": "gunicorn/19.9.0"
},
{
"key": "Access-Control-Allow-Methods",
"value": "POST"
},
{
"key": "Access-Control-Allow-Headers",
"value": "Content-Type, X-CSRF-Token"
},
{
"key": "Access-Control-Allow-Origin",
"value": "None"
},
{
"key": "X-Version",
"value": "0.4.0"
},
{
"key": "X-FB-Backend",
"value": "U5"
},
{
"key": "Content-Security-Policy",
"value": "frame-ancestors https://*.freshbooks.com https://*.freshenv.com http://localhost:4200 https://*.billingarm.com"
},
{
"key": "X-Cache",
"value": "Miss from cloudfront"
},
{
"key": "Via",
"value": "1.1 98aedae6661e3904540676966998ed89.cloudfront.net (CloudFront)"
},
{
"key": "X-Amz-Cf-Pop",
"value": "SEA19-C2"
},
{
"key": "X-Amz-Cf-Id",
"value": "VkEJyM9NHIFX2cXfSiC6nVzflt1xmKXsN2kfTozCtT80XmkilZ-YcQ=="
}
],
"cookie": [
],
"body": "{\n \"cc_token\": \"11223344556677\"\n}"
}
]
}