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