Chilkat Online Tools

Android / New FreshBooks / Provision FreshBooks Payments

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "fname": "Marshall",
    //   "lname": "Johnston",
    //   "email": "api.freshbooks@gmail.com",
    //   "orgname": "Kevin's Corral",
    //   "redirect_base_uri": "https://my.freshbooks.com/#/gatewayConnectRedirect/fbpay/",
    //   "country": "CA",
    //   "allow_multiple_provision": true
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("fname","Marshall");
    json.UpdateString("lname","Johnston");
    json.UpdateString("email","api.freshbooks@gmail.com");
    json.UpdateString("orgname","Kevin's Corral");
    json.UpdateString("redirect_base_uri","https://my.freshbooks.com/#/gatewayConnectRedirect/fbpay/");
    json.UpdateString("country","CA");
    json.UpdateBool("allow_multiple_provision",true);

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken("<access_token>");
    http.SetRequestHeader("Content-Type","application/json");

    CkHttpResponse resp = http.PostJson3("https://api.freshbooks.com/payments/account/{{accountId}}/gateway/fbpay","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    resp.GetBodySb(sbResponseBody);

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    int respStatusCode = resp.get_StatusCode();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, resp.header());
        Log.i(TAG, "Failed.");

        return;
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "fname": "Marshall",
    "lname": "Johnston",
    "email": "api.freshbooks@gmail.com",
    "orgname": "Kevin\'s Corral",
    "redirect_base_uri": "https://my.freshbooks.com/#/gatewayConnectRedirect/fbpay/",
    "country": "CA",
    "allow_multiple_provision": true
}'
https://api.freshbooks.com/payments/account/{{accountId}}/gateway/fbpay

Postman Collection Item JSON

{
  "name": "Provision FreshBooks Payments",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"fname\": \"Marshall\",\n    \"lname\": \"Johnston\",\n    \"email\": \"api.freshbooks@gmail.com\",\n    \"orgname\": \"Kevin's Corral\",\n    \"redirect_base_uri\": \"https://my.freshbooks.com/#/gatewayConnectRedirect/fbpay/\",\n    \"country\": \"CA\",\n    \"allow_multiple_provision\": true\n}"
    },
    "url": {
      "raw": "https://api.freshbooks.com/payments/account/{{accountId}}/gateway/fbpay",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "payments",
        "account",
        "{{accountId}}",
        "gateway",
        "fbpay"
      ]
    },
    "description": "This endpoint is used to provision the ability to use FreshBooks Payments on your invoices. This is typically called at the beginning of new account setup. if you create a new account via the API and don't call this endpoint you will have to manually provision your payment processing account from the settings under \"Accept Online Payments\"."
  },
  "response": [
    {
      "name": "Add FreshBooks Payments",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"fname\": \"Marshall\",\n    \"lname\": \"Johnston\",\n    \"email\": \"mjohnston@freshbooks.com\",\n    \"orgname\": \"Kevin's Corral\",\n    \"redirect_base_uri\": \"https://my.freshbooks.com/#/gatewayConnectRedirect/fbpay/\",\n    \"country\": \"CA\",\n    \"allow_multiple_provision\": true\n}"
        },
        "url": {
          "raw": "https://my.freshbooks.com/service/api/payments/account/lwy0vG/gateway/fbpay",
          "protocol": "https",
          "host": [
            "my",
            "freshbooks",
            "com"
          ],
          "path": [
            "service",
            "api",
            "payments",
            "account",
            "lwy0vG",
            "gateway",
            "fbpay"
          ]
        }
      },
      "status": "CREATED",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/vnd.api+json"
        },
        {
          "key": "X-CardApp-Version",
          "value": "1904.32.0"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABV1FUDwYGV1QTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FAkpXURQRTEVURAkRQ1VWEUgEA0QHTwNBFlJQQwRAT0MEQA0RRFQEXAJbUF8RDxZoVlYSAUZXSj0UBhFfF0oBXWdSUEMEQEMdUR9SSgQDVFZSCgoJXFRaBwgEVFIDGgFVV09AAlsAWwsJUAAHUApXCQMGUkYaUQAKEF1u"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Wed, 25 Apr 2018 16:57:41 GMT"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "Content-Length",
          "value": "4"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Date",
          "value": "Thu, 25 Apr 2019 16:57:41 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17366-MDW"
        },
        {
          "key": "X-Cache",
          "value": "MISS"
        },
        {
          "key": "X-Cache-Hits",
          "value": "0"
        },
        {
          "key": "Country",
          "value": "CA"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains; preload"
        }
      ],
      "cookie": [
      ],
      "body": "null"
    }
  ]
}