Android™ Stripe: Update a Card

Back to Index

Updates only some card details, like the billing address or expiration date, you can do so without having to re-enter the full card details.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL \
   -u STRIPE_SECRET_KEY: \
   -d name="Liam Thomas" \
   -X POST

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_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL
    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("name","Liam Thomas");

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

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

    String id;
    String object;
    boolean address_city;
    boolean address_country;
    boolean address_line1;
    boolean address_line1_check;
    boolean address_line2;
    boolean address_state;
    boolean address_zip;
    boolean address_zip_check;
    String brand;
    String country;
    String customer;
    boolean cvc_check;
    boolean dynamic_last4;
    int exp_month;
    int exp_year;
    String fingerprint;
    String funding;
    String last4;
    String name;
    boolean tokenization_method;

    id = jsonResponse.stringOf("id");
    object = jsonResponse.stringOf("object");
    address_city = jsonResponse.IsNullOf("address_city");
    address_country = jsonResponse.IsNullOf("address_country");
    address_line1 = jsonResponse.IsNullOf("address_line1");
    address_line1_check = jsonResponse.IsNullOf("address_line1_check");
    address_line2 = jsonResponse.IsNullOf("address_line2");
    address_state = jsonResponse.IsNullOf("address_state");
    address_zip = jsonResponse.IsNullOf("address_zip");
    address_zip_check = jsonResponse.IsNullOf("address_zip_check");
    brand = jsonResponse.stringOf("brand");
    country = jsonResponse.stringOf("country");
    customer = jsonResponse.stringOf("customer");
    cvc_check = jsonResponse.IsNullOf("cvc_check");
    dynamic_last4 = jsonResponse.IsNullOf("dynamic_last4");
    exp_month = jsonResponse.IntOf("exp_month");
    exp_year = jsonResponse.IntOf("exp_year");
    fingerprint = jsonResponse.stringOf("fingerprint");
    funding = jsonResponse.stringOf("funding");
    last4 = jsonResponse.stringOf("last4");
    name = jsonResponse.stringOf("name");
    tokenization_method = jsonResponse.IsNullOf("tokenization_method");

  }

  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": "card_1BnETKGswQrCoh0Xhu1A6BfL",
  "object": "card",
  "address_city": null,
  "address_country": null,
  "address_line1": null,
  "address_line1_check": null,
  "address_line2": null,
  "address_state": null,
  "address_zip": null,
  "address_zip_check": null,
  "brand": "Visa",
  "country": "US",
  "customer": "cus_CBbg3iRMzWBjoe",
  "cvc_check": null,
  "dynamic_last4": null,
  "exp_month": 8,
  "exp_year": 2019,
  "fingerprint": "F9mANtIt1TaukpRJ",
  "funding": "credit",
  "last4": "4242",
  "metadata": {},
  "name": "Liam Thomas",
  "tokenization_method": null
}