Perl 在卷曲中为客户添加额外卡片?

Perl 在卷曲中为客户添加额外卡片?,perl,stripe-payments,Perl,Stripe Payments,我在想办法解决这个问题。基本上,它看起来有很多PHP/Ruby/Node等模块,但同样缺少Perl模块(Business::Stripe,自2012年以来就没有更新过!) 所以,我求助于使用curl进行自己的更新。这有点混乱,因为我使用Perl模块创建基本的客户,然后使用curl查询将客户订阅到包中(因为Perl模块不提供“计划”作为功能) 然后订阅: my $sub = `curl https://api.stripe.com/v1/subscriptions -u $key: -d p

我在想办法解决这个问题。基本上,它看起来有很多PHP/Ruby/Node等模块,但同样缺少Perl模块(Business::Stripe,自2012年以来就没有更新过!)

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

然后订阅:

   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:/)


提前谢谢

嗯,我就知道这会发生!!!!发帖几分钟后,我发现:

因此,解决方案是通过以下方式传递令牌:

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模块,用于以编程方式进行操作:


出于性能/安全方面的考虑,您可能最好使用LWP或其他工具,而不是直接使用curl。
$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
    };