Permalink
Browse files

BUG: Fixed issues with being able to update the cancel at end of peri…

…od flag.
  • Loading branch information...
1 parent 57ba08c commit 195c02fd043b6499f8a5baa854921c362db42f6c @gdey committed Mar 4, 2012
Showing with 30 additions and 5 deletions.
  1. +10 −3 lib/WWW/Chargify/HTTP.pm
  2. +1 −1 lib/WWW/Chargify/Role/FromHash.pm
  3. +19 −1 lib/WWW/Chargify/Subscription.pm
View
@@ -91,15 +91,15 @@ sub post {
my $path = join '/', @path;
debug('Path: '.$path.'Body: '.Dumper($body) );
- $self->make_request( POST => $path, $options // {}, $body // "{}");
+ $self->make_request( POST => $path, $options // {}, $body // {});
}
sub put {
my ($self, @path) = @_;
my $body = pop @path if ref($path[-1]) eq 'HASH';
my $options = pop @path if ref($path[-1]) eq 'HASH';
my $path = join '/', grep { defined } @path;
debug('Path: '.$path.'Body: '.Dumper($body) );
- $self->make_request( PUT => $path, $options // {}, $body // "{}");
+ $self->make_request( PUT => $path, $options // {}, $body // {});
}
sub get {
@@ -140,8 +140,14 @@ sub check_response_code {
$error_type = 'AuthorizationError' if $code eq '403';
$error_type = 'ServerError' if $code eq '500';
$error_type = 'DownForMaintenance' if $code eq '503';
+ my $content = $response->content;
if( $response->content !~ /^\s*$/ ) {
- $errors = JSON::decode_json( $response->content )->{errors};
+ my $obj = JSON::decode_json( $response->content);
+ if (ref($obj) eq 'HASH'){
+ $errors =$obj->{errors};
+ } elsif ( ref($obj) eq 'ARRAY' ){
+ $errors = $obj->[1];
+ };
}
die WWW::Chargify::Exception->new(
response => $response,
@@ -182,6 +188,7 @@ sub make_request {
return wantarray? ($value,$response) : $value;
}
+ debug("Body: " . Dumper($content_body)) if $content_body;
#TODO: Need to handle errors here.
$self->check_response_code($response, $content_body);
return wantarray? (undef,$response) : undef;
@@ -87,7 +87,7 @@ sub _to_hash{
my $reader = $attribute->get_read_method;
my $value = $self->$reader;
- next unless $value;
+ next unless defined $value;
my $key = $attribute->has_APIAttributeName
? $attribute->APIAttributeName
@@ -49,7 +49,12 @@ use WWW::Chargify::Migration;
has created_at => ( is => 'rw', isa => 'DateTime', coerce => 1, );
has updated_at => ( is => 'rw', isa => 'DateTime', coerce => 1, );
has canceled_at => ( is => 'rw', isa => 'DateTime', coerce => 1, );
- has delayed_cancel_at => ( is => 'rw', isa => 'DateTime', coerce => 1, );
+ has delayed_cancel_at => ( is => 'rw', isa => 'DateTime', coerce => 1,
+ predicate => 'has_delayed_cancel_at',
+ traits => [qw/Chargify::APIAttribute/],
+ isAPIUpdatable => 0,
+ );
+
has customer => ( is => 'rw',
isa => 'WWW::Chargify::Customer' ,
);
@@ -368,6 +373,19 @@ use WWW::Chargify::Migration;
return $self->_from_hash( http => $http, config => $http->config, hash => $object->{$self->_hash_key} );
}
+ sub reactivate {
+ my ($self, %args) = @_;
+
+ return if $self->state eq 'active' and !$self->cancel_at_end_of_period;
+ my $http = $self->http;
+ my $body = {};
+ $body->{include_trial} = !!$args{include_trial} if exists $args{include_trial};
+ my ($object, $response) = $http->put( $self->_resource_key, $self->id, reactivate => $body );
+ return $self->_from_hash( http => $http, config => $http->config, hash => $object->{$self->_hash_key} );
+ }
+
+
+
# curl -u $ENV{APIKEY}:x -X PUT "https://$ENV{SUBDOMAIN}.chargify.com/subscriptioF "subscription[id]=1301020" -F "subscription[vault_token]=5436078" -F "subscription[next_billing_at]=2012-02-20T22:40:58

0 comments on commit 195c02f

Please sign in to comment.