Question

I am able to successfully create a token, then create a new customer enrolling them in a particular subscription plan.

I cannot figure out how to capture the customer_id that is created for them by Stripe. I need this in order to make changes later (change plan, update CC, etc.). The code I have for creating the customer is below (I use a reader to get fname, lname, etc. and excluded that here for brevity):

private StripeCustomer CreateCustomer()
{
    NameValueCollection nvc = Request.Form;
    string tokenID = nvc["stripeToken"];

    if (tokenID != null)
    {
        var tokenService = new StripeTokenService();
        StripeToken stripeToken = tokenService.Get(tokenID);
    }

    var myCustomer = new StripeCustomerCreateOptions();
    myCustomer.Email = email;
    myCustomer.Description = fname + " " + lname + " (" + email + ")";
    myCustomer.TokenId = tokenID;

    string plan = "basic";

    myCustomer.PlanId = plan;

    var customerService = new StripeCustomerService();

    StripeCustomer CurrentCustomer = customerService.Create(myCustomer);
}

Maybe I am thinking about this incorrectly (must be), but I was looking for the token to provide the CustomerID initially. Here is what that provides:

id: tok_102znI2MdvjLMWitzgclEEcg
livemode: false
created: 1385241151
used: false
object: "token"
type: "card"
card:
    id: card_102znI2MdvjLMWitq44B0MY7
    object: "card"
    last4: "4242"
    type: "Visa"
    exp_month: 12
    exp_year: 2021
    fingerprint: "V2WUOPIgMkP5DGGe"
    customer: null
    country: "US"
    name: null
    address_line1: null
    address_line2: null
    address_city: null
    address_state: null
    address_zip: null
    address_country: null

The token is passed back to me before the customer is created, so that obviously doesn't work.

Was it helpful?

Solution

Chris F had the right idea.

After

StripeCustomer CurrentCustomer = customerService.Create(myCustomer);

I simply needed to add something like

string custid = CurrentCustomer.id;

Then add custid to my database.

OTHER TIPS

You can do this also by :

StripeCustomer currentCustomer = customerService.Create(myCustomer);
currentCustomer.StripeCardList.StripeCards.FirstOrDefault().CustomerId;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top