Android™ Stripe: Update a Customer

Back to Index

Updates the specified customer by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

Documentation: https://stripe.com/docs/api/curl#update_customer

CURL Command

curl -X POST https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq \
   -u STRIPE_SECRET_KEY: \
   -d description="Customer for isabella.williams@example.com"

Android™ Example

// 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);

    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    rest.AddQueryParam("description","Customer for isabella.williams@example.com");

    String strResponseBody = rest.fullRequestFormUrlEncoded("POST","/v1/customers/cus_CBbgVLJqv487Oq");
    if (rest.get_LastMethodSuccess() != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.Load(strResponseBody);

    String id;
    String object;
    int account_balance;
    int created;
    String currency;
    boolean default_source;
    boolean delinquent;
    String description;
    boolean discount;
    boolean email;
    boolean livemode;
    boolean shipping;
    String sourcesObject;
    boolean sourcesHas_more;
    int sourcesTotal_count;
    String sourcesUrl;
    String subscriptionsObject;
    boolean subscriptionsHas_more;
    int subscriptionsTotal_count;
    String subscriptionsUrl;
    int i;
    int count_i;

    id = jsonResponse.stringOf("id");
    object = jsonResponse.stringOf("object");
    account_balance = jsonResponse.IntOf("account_balance");
    created = jsonResponse.IntOf("created");
    currency = jsonResponse.stringOf("currency");
    default_source = jsonResponse.IsNullOf("default_source");
    delinquent = jsonResponse.BoolOf("delinquent");
    description = jsonResponse.stringOf("description");
    discount = jsonResponse.IsNullOf("discount");
    email = jsonResponse.IsNullOf("email");
    livemode = jsonResponse.BoolOf("livemode");
    shipping = jsonResponse.IsNullOf("shipping");
    sourcesObject = jsonResponse.stringOf("sources.object");
    sourcesHas_more = jsonResponse.BoolOf("sources.has_more");
    sourcesTotal_count = jsonResponse.IntOf("sources.total_count");
    sourcesUrl = jsonResponse.stringOf("sources.url");
    subscriptionsObject = jsonResponse.stringOf("subscriptions.object");
    subscriptionsHas_more = jsonResponse.BoolOf("subscriptions.has_more");
    subscriptionsTotal_count = jsonResponse.IntOf("subscriptions.total_count");
    subscriptionsUrl = jsonResponse.stringOf("subscriptions.url");
    i = 0;
    count_i = jsonResponse.SizeOfArray("sources.data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        i = i + 1;
        }

    i = 0;
    count_i = jsonResponse.SizeOfArray("subscriptions.data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        i = i + 1;
        }


  }

  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."
  }
}

Sample JSON Response Body

{
  "id": "cus_CBbgVLJqv487Oq",
  "object": "customer",
  "account_balance": 0,
  "created": 1516662781,
  "currency": "usd",
  "default_source": null,
  "delinquent": false,
  "description": "Customer for isabella.williams@example.com",
  "discount": null,
  "email": null,
  "livemode": false,
  "metadata": {},
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/sources"
  },
  "subscriptions": {
    "object": "list",
    "data": [
    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_CBbgVLJqv487Oq/subscriptions"
  }
}