asp.netstripe-paymentspayment-gatewaypayment-processing

How to retrieve card detail from Stripe Customer Id


Hi I am using stripe process for an payment and I am generating Stripe customer Id as from below code.

  StripeCustomerId = CreateStripeCustomer(fname, lname, Email, objStripeRequestOptions);

Also

IEnumerable<StripeCard> AllStripeCardResponse = cardService.List(StripeCustomerId);
string strLast4 = CardNumber.Replace(" ", "").Substring(CardNumber.Replace(" ", "").Length - 4);
dynamic ExistingCard = (from x in AllStripeCardResponse where x.Last4 == strLast4 & x.ExpirationMonth == Convert.ToInt32(Month.Trim()) & x.ExpirationYear == Convert.ToInt32(Year.Trim()) select x).ToList();

it is giving existing card as 0

Can any one let me know how can I fetch Card Detail like card number, Name, Exp Month Year from Generated Stripe Customer Id?


Solution

  • You can't retrieve whole card info.
    You can get some info from the source object which is present in the customer API.
    Retrieving the source will provide you last 4 digit of card number and expiry date.

        StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4ol‌fQ2");
    
        StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4ol‌​fQ2");
    
        var customerService = new StripeCustomerService();
        StripeCustomer customer = customerService.Get("cus_BwS21a7fAH22uk");
    

    , in response of customer you will have source attribute. please see the JSON response returned. it contains source list(lists of cards added.)

    you will get sample object similar to this , here you can see last 4 digit of card is returned as object in my case it is 1111

    #<Stripe::ListObject:0x5ea1a78> JSON: {
      "object": "list",
      "data": [
        {"id":"card_1BY6nrCaMyPmWTcG3uosK2up","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_BvylB8PAVap2JQ","cvc_check":"pass","dynamic_last4":null,"exp_month":12,"exp_year":2017,"fingerprint":"yE1mPcIGvqTYGcxQ","funding":"unknown","last4":"1111","metadata":{},"name":null,"tokenization_method":null}
      ],
      "has_more": false,
      "total_count": 1,
      "url": "/v1/customers/cus_BvylB8PAVap2JQ/sources"
    }
    

    Also See Below

    var stripecard = "cus_BwS21a7fAH22uk";
    StripeCustomer customer;
    StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["StripeApiKey"].ToString());
    var customerService = new StripeCustomerService();
    customer = customerService.Get(stripecard);
    ViewBag.last4card = customer.Sources.Data[0].Card.Last4.ToString();
    ViewBag.ExpMonth = customer.Sources.Data[0].Card.ExpirationMonth.ToString();
    ViewBag.ExpYear = customer.Sources.Data[0].Card.ExpirationYear.ToString();
    ViewBag.Name = customer.Sources.Data[0].Card.Name.ToString();