Reputation: 575
I am integrating Stripe Payment module in my application. In that I use this Stripe Library.
Now using this code I generating token. Using this token I need card id
before payment
.
How to get this card id'. ?
Here I show you response of Stripe.
When I enter Card Information about the 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 response :
{
"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 created I need this card id :
"card": {
"id": "card_14WdJ02eZvKYlo2C5nE5XjtP",
}
Hope you get my question.
Upvotes: 1
Views: 4565
Reputation: 51
As you can see in the response from stripe, you can simple get your card id and all other fields from the token object you get in response as follows:
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.
Upvotes: 4
Reputation: 575
After Generating token Use this...
Customer.all(new HashMap<String, Object>());
Using this finally i got Cardid which i want.
Here is the total response of Customer.
{
"data": [
com.stripe.model.Customer JSON: {
"object": "customer",
"created": 1410001523,
"id": "cus_4j9JlwfZ5arO4M",
"livemode": false,
"description": null,
"email": "[email protected]",
"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": "[email protected]",
"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 it may help for You. Thanks
Upvotes: 2
Reputation: 12170
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 the model definitions of their Java API and usage examples in their unit tests.
Upvotes: 1