Add an extra card for a Stripe user to Curl?

I am trying to get around this. Basically it looks like there is a ton of PHP / Ruby / Node etc. Modules, but again Perl one is sorely lacking (Business :: Stripe, which hasn't been updated since 2012!)

So, I have resorted to my own updates using curl. It's a bit messy as I used the Perl module to create a basic client and then curl to subscribe to the package (since the Perl module doesn't offer "plans" as a feature)

  use Business::Stripe;
  my $stripe     = Business::Stripe->new(
    -api_key         => $CFG->{stripe_mode}
  );

  my $cid = $stripe->customers_create(
    card => $_[2],
    email => $in->{email},
    description => 'For Site Membership'
  );

      

Then subscribe to:

   my $sub = `curl https://api.stripe.com/v1/subscriptions -u $key: -d plan=name_$in->{package} -d customer=$cid`;
   my $json = decode_json($sub);

      

Now this works ... but the problem I am having is how to add a new card to this client?

I can get the client object back:

   my $sub = `curl https://api.stripe.com/v1/customers/cus_xxxx -u sk_test_KEY:`;
   my $json = decode_json($sub);

      

... and that gives me all the information about the user. But how do I add a new card for them? I already have some code that asks for all the information about the card and then passes back the token (which the card is associated with), but I'm focused on the next step. I have tried googling and I am not coming up with anything useful (there are tons of posts about this with ruby ​​/ node / php example, but no pure curl: /)

Thanks in advance!

+3


source to share


1 answer


Heh, I knew it was going to happen !!!! Literally a few minutes after posting this question, I came across:

https://stripe.com/docs/api#card_object

So the solution is to simply pass the token through:

my $res = `curl https://api.stripe.com/v1/customers/$USER->{stripe_customer_id}/sources -u $key: -d source=$in->{token}`;

      

... and then decode:

my $json = decode_json($res);

      

... and returns an object with a new map:



$VAR1 = {
      'object' => 'card',
      'address_zip' => undef,
      'address_state' => undef,
      'fingerprint' => 'lRvQRC14boreOKjk',
      'brand' => 'Visa',
      'tokenization_method' => undef,
      'dynamic_last4' => undef,
      'address_zip_check' => undef,
      'address_line2' => undef,
      'funding' => 'credit',
      'exp_month' => 12,
      'address_city' => undef,
      'metadata' => {},
      'id' => 'card_xxxx',
      'country' => 'US',
      'name' => 'andy@domain.co.uk',
      'exp_year' => 2019,
      'address_line1' => undef,
      'address_country' => undef,
      'cvc_check' => 'pass',
      'customer' => 'cus_xxxx',
      'last4' => '4242',
      'address_line1_check' => undef
    };

      

... and of course, the additional map associated with the user is now displayed:

enter image description here

Hope this helps save someone else the hassle :)

Also, I came across a much better Perl module for programming it:

http://search.cpan.org/~rconover/Net-Stripe-0.30/lib/Net/Stripe.pm

+2


source







All Articles