Chilkat Online Tools

DataFlex / New FreshBooks / 3. [STRIPE] - Save Payment Method to Recurring Profile

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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
    //       }
    //     ]
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "credit_card.saved_to_system_id" "E86Qd" To iSuccess
    Get ComUpdateInt Of hoJson "credit_card.card_holder_user_id" 11223344 To iSuccess
    Get ComUpdateBool Of hoJson "credit_card.access.system" True To iSuccess
    Get ComUpdateBool Of hoJson "credit_card.access.client" False To iSuccess
    Get ComUpdateInt Of hoJson "credit_card.access.invoice_profiles[0]" 26347 To iSuccess
    Get ComUpdateString Of hoJson "credit_card.credit_card_tokens[0].payment_method_id" "pm_d87sh438shuiasf4289437u" To iSuccess
    Get ComUpdateString Of hoJson "credit_card.credit_card_tokens[0].gateway_name" "stripe" To iSuccess
    Get ComUpdateBool Of hoJson "credit_card.credit_card_tokens[0].is_primary" True To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.freshbooks.com/payments/account/E86Qp/credit-card" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}