PowerBuilder / New FreshBooks / 3. [STRIPE] - Save Payment Method to Recurring Profile
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
// 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": "E86Qd",
// "card_holder_user_id": 11223344,
// "access": {
// "system": true,
// "client": false,
// "invoice_profiles": [
// 26347
// ]
// },
// "credit_card_tokens": [
// {
// "payment_method_id": "pm_d87sh438shuiasf4289437u",
// "gateway_name": "stripe",
// "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","E86Qd")
loo_Json.UpdateInt("credit_card.card_holder_user_id",11223344)
loo_Json.UpdateBool("credit_card.access.system",1)
loo_Json.UpdateBool("credit_card.access.client",0)
loo_Json.UpdateInt("credit_card.access.invoice_profiles[0]",26347)
loo_Json.UpdateString("credit_card.credit_card_tokens[0].payment_method_id","pm_d87sh438shuiasf4289437u")
loo_Json.UpdateString("credit_card.credit_card_tokens[0].gateway_name","stripe")
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/E86Qp/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
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_Json
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"credit_card": {
"saved_to_system_id": "E86Qd",
"card_holder_user_id": 11223344,
"access": {
"system": true,
"client": false,
"invoice_profiles": [26347]
},
"credit_card_tokens": [
{
"payment_method_id": "pm_d87sh438shuiasf4289437u",
"gateway_name": "stripe",
"is_primary": true
}
]
}
}'
https://api.freshbooks.com/payments/account/E86Qp/credit-card
Postman Collection Item JSON
{
"name": "3. [STRIPE] - Save Payment Method to Recurring Profile",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"credit_card\": {\n \"saved_to_system_id\": \"E86Qd\",\n \"card_holder_user_id\": 11223344,\n \"access\": {\n \"system\": true,\n \"client\": false,\n \"invoice_profiles\": [26347]\n },\n \"credit_card_tokens\": [\n {\n \"payment_method_id\": \"pm_d87sh438shuiasf4289437u\",\n \"gateway_name\": \"stripe\",\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"
]
},
"description": "You will then pass the pm_id from Step 1 to a specific invoice profile. \n\nThe invoice profile can be found in the UI or as a response when created. "
},
"response": [
]
}