Stripe card id using token in android

I am connecting the Stripe Payment module in my application. In this I use this Stripe Library. Now using this code I am generating a token. Using this token, I need a mapid

. before payment

How to get this card id'. ?

Here I am showing you Stripe's answer.

When I enter the Card Information Card Like this:

Stripe_Token::create(array(
"card" => array(
"number" => "4242424242424242",
"exp_month" => 8,
"exp_year" => 2015,
"cvc" => "314"
)
));

      

After that Stripe give me this answer:

{
"id": "tok_14WdJ02eZvKYlo2CyaZ49ZP7",
"livemode": false,
"created": 1409272314,
"used": false,
"object": "token",
"type": "card",
"card": {
"id": "card_14WdJ02eZvKYlo2C5nE5XjtP",
"object": "card",
"last4": "4242",
"brand": "Visa",
"funding": "credit",
"exp_month": 8,
"exp_year": 2015,
"fingerprint": "Xt5EWLLDS7FJjR1c",
"country": "US",
"name": null,
"address_line1": null,
"address_line2": null,
"address_city": null,
"address_state": null,
"address_zip": null,
"address_country": null,
"customer": null
}
}

      

Before payment and after token creation I need this card ID:

"card": {
"id": "card_14WdJ02eZvKYlo2C5nE5XjtP",
}

      

I hope you get my question.

+3


source to share


3 answers


After creating the token Use this ...

Customer.all(new HashMap<String, Object>());

      

Using this finally I got the Cardid I want.



Here is the complete answer from the Client.

{
  "data": [
    com.stripe.model.Customer JSON: {
      "object": "customer",
      "created": 1410001523,
      "id": "cus_4j9JlwfZ5arO4M",
      "livemode": false,
      "description": null,
      "email": "customer@example.com",
      "delinquent": false,
      "metadata": {
      },
      "subscriptions": {
        "object": "list",
        "total_count": 0,
        "has_more": false,
        "url": "/v1/customers/cus_4j9JlwfZ5arO4M/subscriptions",
        "data": [

        ]
      },
      "discount": null,
      "account_balance": 0,
      "currency": "usd",
      "cards": {
        "object": "list",
        "total_count": 1,
        "has_more": false,
        "url": "/v1/customers/cus_4j9JlwfZ5arO4M/cards",
        "data": [
          {
            "id": "card_14Zh0M2eZvKYlo2CAl9gQ262",
            "object": "card",
            "last4": "4242",
            "brand": "Visa",
            "funding": "credit",
            "exp_month": 12,
            "exp_year": 2015,
            "fingerprint": "Xt5EWLLDS7FJjR1c",
            "country": "US",
            "name": "akinci_yasin@hotmail.com",
            "address_line1": null,
            "address_line2": null,
            "address_city": null,
            "address_state": null,
            "address_zip": null,
            "address_country": null,
            "cvc_check": null,
            "address_line1_check": null,
            "address_zip_check": null,
            "customer": "cus_4j9JlwfZ5arO4M"
          }
        ]
      },
      "default_card": "card_14Zh0M2eZvKYlo2CAl9gQ262"
    },
    #<com.stripe.model.Customer[...] ...>,
    #<com.stripe.model.Customer[...] ...>
  ],
  "has_more": false
}

      

Hope this helps you. thank

+2


source


As you can see in the response from stripe, you can simply get your card id and all other fields from the token object you receive in response like this:

String card_id = token.getCard().getId(); // to get card id
String id = token.getId(); // to get this "id": "tok_14WdJ02eZvKYlo2CyaZ49ZP7"
boolean live_mode = token.getLivemode(); // to get livemode
String last_four = token.getCard().getLast4(); // to get last 4

      



where token is the response object.

+4


source


Using gson:

package gson.sample.one;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class gsonsample
{ 
    public class card {
        public String id;
        public String object;
        public String last4;
        public String brand;
        public String funding;
        public int exp_month;
        public int exp_year;
        public String fingerprint;
        public String country;
        public String name;
        public String address_line1;
        public String address_line2;
        public String address_city;
        public String address_state;
        public String address_zip;
        public String address_country;
        public String customer;
    }

    public class Response {
        public String id;
        public Boolean livemode;
        public int created;
        public String object;
        public String type;
        public card card;
    }

    public static void main(String [] args)
    {
        String json = "{ \"id\": \"tok_14WdJ02eZvKYlo2CyaZ49ZP7\", \"livemode\": false, \"created\": 1409272314, \"used\": false, \"object\": \"token\", \"type\": \"card\", \"card\": { \"id\": \"card_14WdJ02eZvKYlo2C5nE5XjtP\", \"object\": \"card\", \"last4\": \"4242\", \"brand\": \"Visa\", \"funding\": \"credit\", \"exp_month\": 8, \"exp_year\": 2015, \"fingerprint\": \"Xt5EWLLDS7FJjR1c\", \"country\": \"US\", \"name\": null, \"address_line1\": null, \"address_line2\": null, \"address_city\": null, \"address_state\": null, \"address_zip\": null, \"address_country\": null, \"customer\": null } }"; 
        // 
        Gson gson = new GsonBuilder().create();
        Response response = gson.fromJson(json, Response.class);

        String id = response.card.id;

        System.out.println(id);
    }
}

      

Stripe also has these objects defined in their Java API model definitions and usage examples in their unit tests .

+1


source







All Articles