ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm trying to get Net::Stripe to work on my new server, using Perl v5.22.1. I have a *really* annoying issue though! My code is simple:

use Net::Stripe; my $stripe = Net::Stripe->new( api_key => $CFG->{stripe_mode} eq "test" ? $CFG->{stripe_secre +t_test} : $CFG->{stripe_secret_live}, debug => '1', debug_network => '1' ); my $cards = $stripe->get_cards(customer => 'cus_ALXYaoa9Lpo4Gs', +limit => 10);

..and then when running, it gives:

Odd number of elements in anonymous hash at test.cgi line 35.

Using: perl -w -d test.cgi , I am trying to debug it - but when I get to the point it gives that error, I don't see anything helpful. The only part I see is line 541 in /Net/Stripe.pm, which is:

method get_cards(Net::Stripe::Customer|Str $customer, HashRef :$created?, Str :$ending_before?, Int :$limit?, Str :$starting_after?) {

It seems to fatal after that (I added some test code in after, but it doesn't get that far). I'm looked around at the error message on Google, but I can't work out how to debug this further (I'm not a user of Moose myself, so wouldn't have a clue of the above code even looks correct!)

Any suggestions are much appreciated.

Cheers

Andy

Replies are listed 'Best First'.
Re: Net::Stripe, Moose bug?
by choroba (Cardinal) on Apr 12, 2017 at 13:47 UTC
    You seem to be on the right track, but someone has already got further: Pull Request to fix get_cards.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thanks. Thats actually a fix I've already applied :(

      https://github.com/lukec/stripe-perl/issues/33

      This fix already exists in the Stripe.pm version I'm using:
      194c194 < method get_cards(Net::Stripe::Customer|Str :$customer, --- > method get_cards(Net::Stripe::Customer|Str $customer, 203,204c203,204 < $self->_get_collections("customers/$customer/sources", < object => 'card', --- > $self->_get_collections('cards', > id => $customer, 596,598d595 < } < if (my $obj = $args{object}) { < push @path_args, "object=$obj";
      Cheers

      Andy
Re: Net::Stripe, Moose bug?
by Corion (Patriarch) on Apr 12, 2017 at 13:45 UTC

    Your code doesn't have 35 lines.

    Even without installing Net::Stripe, I don't get an error or warning when compiling your code if I comment out use Net::Stripe.

    Please post the real code you are using and ideally, as a command line program since CGI is hopefully not involved here.

      Hi,

      Sorry, here is the full code:

      #!/usr/bin/perl -w # ================================================================== # Test script for Stripe payments use strict; use lib '/srv/www/site.pro/www/cgi-bin/trust/admin'; use Links qw/$USER $IN $DB $CFG/; use CGI::Carp qw(fatalsToBrowser); use Links::SiteHTML; use LWP::Simple; use POSIX qw(ceil); use JSON; Links::init('/srv/www/site.pro/www/cgi-bin/trust/admin'); my $key = $CFG->{stripe_mode} eq "test" ? $CFG->{stripe_secret_test} : + $CFG->{stripe_secret_live}; print "KEY: $key ($CFG->{stripe_mode}) \n"; use Digest::MD5 qw(md5_hex); use Net::Stripe; my $stripe = Net::Stripe->new( api_key => $CFG->{stripe_mode} eq "test" ? $CFG->{stripe_secre +t_test} : $CFG->{stripe_secret_live}, debug => '1', debug_network => '1' ); print $IN->header; use Data::Dumper; print STDERR Dumper(customer => $USER->{stripe_customer_id}, limit + => 10); my $cards = $stripe->get_cards(customer => 'cus_ALXYaoa9Lpo4Gs', l +imit => 10); print $IN->header; use Data::Dumper; print Dumper($cards);


      Line 35 is:

        my $cards = $stripe->get_cards(customer => 'cus_ALXYaoa9Lpo4Gs', limit => 10);

      Thanks!

      Andy
Re: Net::Stripe, Moose bug?
by huck (Prior) on Apr 12, 2017 at 13:49 UTC

    It would help to know what test.cgi line 35 was. Please include a couple of statments before and after as sometimes the place perl identifes the error at is offset because of errors on the previous or following few lines

      Yeah sorry, please see my post above :) (I posted the whole code). It fails on:

      my $cards = $stripe->get_cards(customer => 'cus_ALXYaoa9Lpo4Gs', limit => 10);

      Line 541 in /Net/Stripe.pm

      Cheers

      Andy