line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Stripe::Resource; |
2
|
|
|
|
|
|
|
$Net::Stripe::Resource::VERSION = '0.41'; |
3
|
|
|
|
|
|
|
# ABSTRACT: represent a Resource object from Stripe |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1373
|
use Moose; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
22
|
|
6
|
2
|
|
|
2
|
|
14226
|
use Kavorka; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
16
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'boolean_attributes' => (is => 'ro', isa => 'ArrayRef[Str]'); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
around BUILDARGS => sub { |
11
|
|
|
|
|
|
|
my $orig = shift; |
12
|
|
|
|
|
|
|
my $class = shift; |
13
|
|
|
|
|
|
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Break out the JSON::XS::Boolean values into 1/0 |
16
|
|
|
|
|
|
|
for my $field (keys %args) { |
17
|
|
|
|
|
|
|
if (ref($args{$field}) =~ /^(JSON::XS::Boolean|JSON::PP::Boolean)$/) { |
18
|
|
|
|
|
|
|
$args{$field} = $args{$field} ? 1 : 0; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if (my $s = $args{source}) { |
23
|
|
|
|
|
|
|
if (ref($s) eq 'HASH' && $s->{object} eq 'source') { |
24
|
|
|
|
|
|
|
$args{source} = Net::Stripe::Source->new($s); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
for my $f (qw/card default_card/) { |
29
|
|
|
|
|
|
|
next unless $args{$f}; |
30
|
|
|
|
|
|
|
next unless ref($args{$f}) eq 'HASH'; |
31
|
|
|
|
|
|
|
$args{$f} = Net::Stripe::Card->new($args{$f}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if (my $s = $args{subscription}) { |
35
|
|
|
|
|
|
|
if (ref($s) eq 'HASH') { |
36
|
|
|
|
|
|
|
$args{subscription} = Net::Stripe::Subscription->new($s); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
if (my $s = $args{coupon}) { |
40
|
|
|
|
|
|
|
if (ref($s) eq 'HASH') { |
41
|
|
|
|
|
|
|
$args{coupon} = Net::Stripe::Coupon->new($s); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
if (my $s = $args{discount}) { |
45
|
|
|
|
|
|
|
if (ref($s) eq 'HASH') { |
46
|
|
|
|
|
|
|
$args{discount} = Net::Stripe::Discount->new($s); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
if (my $p = $args{plan}) { |
50
|
|
|
|
|
|
|
if (ref($p) eq 'HASH') { |
51
|
|
|
|
|
|
|
$args{plan} = Net::Stripe::Plan->new($p); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
for my $attr ($class->meta()->get_all_attributes()) { |
56
|
|
|
|
|
|
|
next if !($attr->type_constraint && ( |
57
|
|
|
|
|
|
|
$attr->type_constraint eq 'Bool' || |
58
|
|
|
|
|
|
|
$attr->type_constraint eq 'Maybe[Bool]' || |
59
|
|
|
|
|
|
|
$attr->type_constraint eq 'Maybe[Bool|Object]' |
60
|
|
|
|
|
|
|
)); |
61
|
|
|
|
|
|
|
push @{$args{boolean_attributes}}, $attr->name; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$class->$orig(%args); |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
fun form_fields_for_hashref ( |
68
|
|
|
|
|
|
|
Str $field_name!, |
69
|
|
|
|
|
|
|
HashRef $hashref!, |
70
|
2
|
50
|
|
2
|
|
191707
|
) { |
|
2
|
50
|
|
2
|
|
5
|
|
|
2
|
50
|
|
2
|
|
272
|
|
|
2
|
50
|
|
2
|
|
16
|
|
|
2
|
50
|
|
|
|
5
|
|
|
2
|
50
|
|
|
|
272
|
|
|
2
|
50
|
|
|
|
15
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
537
|
|
|
2
|
|
|
|
|
869
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4
|
|
71
|
2
|
|
|
|
|
5
|
my @field_values; |
72
|
2
|
|
|
|
|
8
|
foreach my $key (sort keys %$hashref) { |
73
|
2
|
|
|
|
|
5
|
my $value = $hashref->{$key}; |
74
|
2
|
|
|
|
|
10
|
my $nested_field_name = sprintf( '%s[%s]', $field_name, $key ); |
75
|
2
|
100
|
|
|
|
7
|
if ( ref( $value ) eq 'HASH' ) { |
76
|
1
|
|
|
|
|
8
|
push @field_values, form_fields_for_hashref( $nested_field_name, $value ); |
77
|
|
|
|
|
|
|
} else { |
78
|
1
|
|
|
|
|
4
|
push @field_values, ( $nested_field_name => $value ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
2
|
|
|
|
|
8
|
return @field_values; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
fun form_fields_for_arrayref ( |
85
|
|
|
|
|
|
|
Str $field_name!, |
86
|
|
|
|
|
|
|
ArrayRef $arrayref!, |
87
|
2
|
50
|
|
2
|
|
6653
|
) { |
|
2
|
50
|
|
2
|
|
6
|
|
|
2
|
50
|
|
2
|
|
257
|
|
|
2
|
50
|
|
1
|
|
16
|
|
|
2
|
50
|
|
|
|
5
|
|
|
2
|
50
|
|
|
|
278
|
|
|
2
|
50
|
|
|
|
14
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
282
|
|
|
1
|
|
|
|
|
660
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
88
|
1
|
|
|
|
|
6
|
my $nested_field_name = sprintf( '%s[]', $field_name ); |
89
|
1
|
|
|
|
|
5
|
return $nested_field_name => $arrayref; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
2
|
50
|
|
2
|
|
3404
|
method fields_for($for) { |
|
2
|
50
|
|
26
|
|
5
|
|
|
2
|
50
|
|
|
|
885
|
|
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
50
|
|
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
36
|
|
93
|
26
|
50
|
|
|
|
84
|
return unless $self->can($for); |
94
|
26
|
|
|
|
|
734
|
my $thingy = $self->$for; |
95
|
26
|
100
|
|
|
|
109
|
return unless defined( $thingy ); |
96
|
2
|
50
|
33
|
|
|
18
|
return ($for => $thingy->id) if $for eq 'card' && ref($thingy) eq 'Net::Stripe::Token'; |
97
|
2
|
50
|
33
|
|
|
8
|
return ($for => $thingy->id) if $for eq 'source' && ref($thingy) eq 'Net::Stripe::Token'; |
98
|
2
|
50
|
|
|
|
7
|
return $thingy->form_fields if ref($thingy) =~ m/^Net::Stripe::/; |
99
|
2
|
50
|
|
|
|
15
|
return form_fields_for_hashref( $for, $thingy ) if ref( $thingy ) eq 'HASH'; |
100
|
2
|
50
|
|
|
|
6
|
return form_fields_for_arrayref( $for, $thingy ) if ref( $thingy ) eq 'ARRAY'; |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
8
|
my $token_id_type = Moose::Util::TypeConstraints::find_type_constraint( 'StripeTokenId' ); |
103
|
2
|
0
|
33
|
|
|
204
|
return form_fields_for_hashref( $for, { token => $thingy } ) |
|
|
|
33
|
|
|
|
|
104
|
|
|
|
|
|
|
if $self->isa( 'Net::Stripe::PaymentMethod' ) && $for eq 'card' && $token_id_type->check( $thingy ); |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
23
|
return ( $for => $self->get_form_field_value( $for ) ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
2
|
50
|
|
2
|
|
3560
|
method form_fields_for(@fields!) { |
|
2
|
50
|
|
2
|
|
7
|
|
|
2
|
|
|
|
|
320
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
6
|
|
110
|
2
|
|
|
|
|
5
|
return map { $self->fields_for( $_ ) } @fields; |
|
26
|
|
|
|
|
54
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
2
|
50
|
|
2
|
|
4595
|
method is_a_boolean(Str $attr!) { |
|
2
|
50
|
|
2
|
|
6
|
|
|
2
|
50
|
|
2
|
|
308
|
|
|
2
|
50
|
|
|
|
15
|
|
|
2
|
50
|
|
|
|
5
|
|
|
2
|
|
|
|
|
356
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
5
|
|
114
|
2
|
50
|
|
|
|
4
|
my %boolean_attributes = map { $_ => 1 } @{$self->boolean_attributes() || []}; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
69
|
|
115
|
2
|
|
|
|
|
13
|
return exists( $boolean_attributes{$attr} ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
2
|
50
|
|
2
|
|
4935
|
method get_form_field_value(Str $attr!) { |
|
2
|
50
|
|
2
|
|
6
|
|
|
2
|
50
|
|
2
|
|
333
|
|
|
2
|
50
|
|
|
|
17
|
|
|
2
|
50
|
|
|
|
5
|
|
|
2
|
|
|
|
|
440
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4
|
|
119
|
2
|
|
|
|
|
57
|
my $value = $self->$attr; |
120
|
2
|
50
|
|
|
|
10
|
return $value if ! $self->is_a_boolean( $attr ); |
121
|
0
|
0
|
0
|
|
|
|
return ( defined( $value ) && $value ) ? 'true' : 'false'; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=pod |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Net::Stripe::Resource - represent a Resource object from Stripe |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
version 0.41 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 boolean_attributes |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Reader: boolean_attributes |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Type: ArrayRef[Str] |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHORS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over 4 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Luke Closs |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Rusty Conover |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Prime Radiant, Inc., (c) copyright 2014 Lucky Dinosaur LLC. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
165
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |