【问题标题】:Add extra card to Stripe customer, in Curl?在 Curl 中向 Stripe 客户添加额外的卡?
【发布时间】:2017-03-24 14:13:35
【问题描述】:

我正在努力解决这个问题。基本上,看起来有大量的 PHP/Ruby/Node 等模块,但又是一个非常缺乏 Perl 的模块(Business::Stripe,自 2012 年以来就没有更新过!)

所以,我求助于使用 curl 进行自己的更新。有点乱,因为我使用 Perl 模块进行基本客户创建,然后使用 curl 查询为他们订阅包(因为 Perl 模块不提供“计划”作为功能)

  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'
  );

然后订阅:

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

现在可以了...但是我遇到的问题是如何向该客户添加新卡?

我可以很好地取回客户对象:

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

...这为我提供了有关用户的所有信息。但是如何为他们添加新卡?我已经获得了询问所有卡信息的代码,然后将令牌(与卡关联的地方)传回,但我对下一步感到困惑。我试过用谷歌搜索,但没有找到任何有用的东西(有很多关于它的帖子,例如 ruby​​/node/php,但没有一个是纯 curl :/)

提前致谢!

【问题讨论】:

  • 出于性能/安全原因,您最好使用 LWP 或其他东西,而不是使用 curl。

标签: perl stripe-payments


【解决方案1】:

哎呀,我就知道会这样!!!!发布后几分钟,我遇到了:

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

所以解决方案是通过以下方式传递令牌:

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

...然后解码:

my $json = decode_json($res);

...这会返回一个带有新卡片的对象:

$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
    };

...果然,它现在显示了与用户关联的额外卡片:

希望这有助于为其他人省去麻烦:)

此外,我还发现了一个更好的 Perl 模块,可以通过编程来实现:

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

【讨论】:

    猜你喜欢
    • 2015-05-08
    • 1970-01-01
    • 2020-08-14
    • 2017-03-13
    • 1970-01-01
    • 2017-04-20
    • 2018-03-04
    • 2015-02-25
    • 1970-01-01
    相关资源
    最近更新 更多