PowerBuilder / New FreshBooks / 2. [FBPAY] - Create Setup Intent Using Payment Method Key
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
integer li_IntVal
string ls_Id
string ls_Gateway_name
string ls_Credit_card_uuid
integer li_Card_holder_user_id
string ls_Saved_to_system_id
string ls_Card_type
string ls_Expiry_year
string ls_Expiry_month
string ls_Last_four_digits
string ls_Card_holder_name
integer li_System
integer li_Client
integer i
integer li_Count_i
// 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.
// {
// "credit_card": {
// "saved_to_system_id": "yDDAb0",
// "card_holder_user_id": 146211,
// "access": {
// "system": false,
// "client": false,
// "invoice_profiles": [
// 33
// ]
// },
// "credit_card_tokens": [
// {
// "token": "token_123",
// "gateway_name": "fbpay",
// "is_primary": true
// }
// ]
// }
// }
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("credit_card.saved_to_system_id","yDDAb0")
loo_Json.UpdateInt("credit_card.card_holder_user_id",146211)
loo_Json.UpdateBool("credit_card.access.system",0)
loo_Json.UpdateBool("credit_card.access.client",0)
loo_Json.UpdateInt("credit_card.access.invoice_profiles[0]",33)
loo_Json.UpdateString("credit_card.credit_card_tokens[0].token","token_123")
loo_Json.UpdateString("credit_card.credit_card_tokens[0].gateway_name","fbpay")
loo_Json.UpdateBool("credit_card.credit_card_tokens[0].is_primary",1)
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Resp = loo_Http.PostJson3("https://api.freshbooks.com/payments/account/{{accountid}}/credit-card","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)
// {
// "credit_card": {
// "credit_card_uuid": "7c8d965555554d40ddde59sadasdc7180asda7ba",
// "card_holder_user_id": 123456,
// "saved_to_system_id": "E86Qd",
// "card_type": "visa",
// "expiry_year": "2024",
// "expiry_month": "9",
// "last_four_digits": "0234",
// "card_holder_name": "John Johnston",
// "access": {
// "system": true,
// "client": false,
// "invoice_profiles": [
// 121212
// ]
// },
// "credit_card_tokens": [
// {
// "id": "fbpay+akdjhadkjashckJNCksajncasc",
// "gateway_name": "fbpay"
// }
// ]
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
ls_Credit_card_uuid = loo_JResp.StringOf("credit_card.credit_card_uuid")
li_Card_holder_user_id = loo_JResp.IntOf("credit_card.card_holder_user_id")
ls_Saved_to_system_id = loo_JResp.StringOf("credit_card.saved_to_system_id")
ls_Card_type = loo_JResp.StringOf("credit_card.card_type")
ls_Expiry_year = loo_JResp.StringOf("credit_card.expiry_year")
ls_Expiry_month = loo_JResp.StringOf("credit_card.expiry_month")
ls_Last_four_digits = loo_JResp.StringOf("credit_card.last_four_digits")
ls_Card_holder_name = loo_JResp.StringOf("credit_card.card_holder_name")
li_System = loo_JResp.BoolOf("credit_card.access.system")
li_Client = loo_JResp.BoolOf("credit_card.access.client")
i = 0
li_Count_i = loo_JResp.SizeOfArray("credit_card.access.invoice_profiles")
do while i < li_Count_i
loo_JResp.I = i
li_IntVal = loo_JResp.IntOf("credit_card.access.invoice_profiles[i]")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("credit_card.credit_card_tokens")
do while i < li_Count_i
loo_JResp.I = i
ls_Id = loo_JResp.StringOf("credit_card.credit_card_tokens[i].id")
ls_Gateway_name = loo_JResp.StringOf("credit_card.credit_card_tokens[i].gateway_name")
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"credit_card": {
"saved_to_system_id": "yDDAb0",
"card_holder_user_id": 146211,
"access": {
"system": false,
"client": false,
"invoice_profiles": [
33
]
},
"credit_card_tokens": [
{
"token": "token_123",
"gateway_name": "fbpay",
"is_primary": true
}
]
}
}'
https://api.freshbooks.com/payments/account/{{accountid}}/credit-card
Postman Collection Item JSON
{
"name": "2. [FBPAY] - Create Setup Intent Using Payment Method Key",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"credit_card\": {\n \"saved_to_system_id\": \"yDDAb0\",\n \"card_holder_user_id\": 146211,\n \"access\": {\n \"system\": false,\n \"client\": false,\n \"invoice_profiles\": [\n 33\n ]\n },\n \"credit_card_tokens\": [\n {\n \"token\": \"token_123\",\n \"gateway_name\": \"fbpay\",\n \"is_primary\": true\n }\n ]\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/payments/account/{{accountid}}/credit-card",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"payments",
"account",
"{{accountid}}",
"credit-card"
]
}
},
"response": [
{
"name": "2. [FBPAY] - Create Setup Intent Using Payment Method Key",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"credit_card\": {\n \"saved_to_system_id\": \"E86Qp\",\n \"card_holder_user_id\": 590529,\n \"access\": {\n \"system\": true,\n \"client\": false,\n \"invoice_profiles\": [\n 26627\n ]\n },\n \"credit_card_tokens\": [\n {\n \"token\": \"1111111\",\n \"gateway_name\": \"fbpay\",\n \"is_primary\": true\n }\n ]\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/payments/account/E86Qp/credit-card",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"payments",
"account",
"E86Qp",
"credit-card"
]
}
},
"status": "CREATED",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Fri, 31 Jul 2020 20:33:18 GMT"
},
{
"key": "Content-Type",
"value": "application/vnd.api+json"
},
{
"key": "Content-Length",
"value": "438"
},
{
"key": "X-CardApp-Version",
"value": "2007.68.0"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABV1FUDwYGV1QTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FAkpXURQRTEVURAkRQ1VWEUgAEFUGURZnW1VAV0tLBEIORhAHUw0CFAZcWkQHABBTQ1IVC0REUAdET1IcURZQCQEBBgBcClIJVwtWVA4bVVNTFBEFVVJRUwBUX1MHAgAAVFFQEk5eA1RLUW8="
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "X-Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31556926; includeSubDomains; preload"
},
{
"key": "Referrer-Policy",
"value": "strict-origin-when-cross-origin"
},
{
"key": "X-RateLimit-Limit",
"value": "600"
},
{
"key": "X-RateLimit-Remaining",
"value": "598"
},
{
"key": "X-RateLimit-Reset",
"value": "1596227656"
},
{
"key": "Retry-After",
"value": "57"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Alt-Svc",
"value": "h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
}
],
"cookie": [
],
"body": "{\n \"credit_card\": {\n \"credit_card_uuid\": \"7c8d965555554d40ddde59sadasdc7180asda7ba\",\n \"card_holder_user_id\": 123456,\n \"saved_to_system_id\": \"E86Qd\",\n \"card_type\": \"visa\",\n \"expiry_year\": \"2024\",\n \"expiry_month\": \"9\",\n \"last_four_digits\": \"0234\",\n \"card_holder_name\": \"John Johnston\",\n \"access\": {\n \"system\": true,\n \"client\": false,\n \"invoice_profiles\": [121212]\n },\n \"credit_card_tokens\": [\n {\n \"id\": \"fbpay+akdjhadkjashckJNCksajncasc\",\n \"gateway_name\": \"fbpay\"\n }\n ]\n }\n}"
}
]
}