line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
## Stripe API - ~/lib/Net/API/Stripe/Product/PackageDimension.pm |
3
|
|
|
|
|
|
|
## Version v0.100.1 |
4
|
|
|
|
|
|
|
## Copyright(c) 2020 DEGUEST Pte. Ltd. |
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
6
|
|
|
|
|
|
|
## Created 2019/11/02 |
7
|
|
|
|
|
|
|
## Modified 2020/05/16 |
8
|
|
|
|
|
|
|
## |
9
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
package Net::API::Stripe::Product::PackageDimension; |
11
|
|
|
|
|
|
|
BEGIN |
12
|
|
|
|
|
|
|
{ |
13
|
2
|
|
|
2
|
|
918
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
65
|
|
14
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
59
|
|
15
|
2
|
|
|
2
|
|
10
|
use parent qw( Net::API::Stripe::Generic ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
16
|
2
|
|
|
2
|
|
150
|
use vars qw( $VERSION ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
115
|
|
17
|
2
|
|
|
2
|
|
54
|
our( $VERSION ) = 'v0.100.1'; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
42
|
|
21
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1273
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub init |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
1
|
1
|
3752604
|
my $self = shift( @_ ); |
26
|
|
|
|
|
|
|
# Default to using the imperial measurement, ie default measurement system in the U.S. |
27
|
|
|
|
|
|
|
# User needs to activate the metric system |
28
|
1
|
|
|
|
|
80
|
$self->{use_metric} = 0; |
29
|
1
|
|
|
|
|
46
|
$self->SUPER::init( @_ ); |
30
|
1
|
|
|
|
|
4
|
return( $self ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
1
|
|
sub height { return( shift->_set_get_convert_number( 'height', @_ ) ); } |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
0
|
1
|
|
sub length { return( shift->_set_get_convert_weight( 'length', @_ ) ); } |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub use_metric |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
40
|
0
|
0
|
|
|
|
|
if( @_ ) |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
# Check provided and convert data on the fly |
43
|
0
|
|
|
|
|
|
my $val = shift( @_ ); |
44
|
0
|
|
|
|
|
|
$self->{use_metric} = $val; |
45
|
|
|
|
|
|
|
# Convert all data to metric, so it can be converted back after into inch and ounces when used for Stripe api calls |
46
|
0
|
|
|
|
|
|
foreach my $k ( qw( height length width ) ) |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
0
|
|
|
|
|
next if( !CORE::length( $self->{ $k } ) ); |
49
|
0
|
|
|
|
|
|
my $v = $self->_set_get_convert_size( $k, $self->{ $k } ); |
50
|
0
|
|
|
|
|
|
$self->{ $k } = $v; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
0
|
|
|
|
|
if( CORE::length( $self->{weight} ) ) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
my $v = $self->_set_get_convert_weight( 'weight', $self->{weight} ); |
55
|
0
|
|
|
|
|
|
$self->{weight} = $v; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return( $self->{use_metric} ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
0
|
1
|
|
sub weight { return( shift->_set_get_number( 'weight', @_ ) ); } |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
0
|
1
|
|
sub width { return( shift->_set_get_convert_size( 'width', @_ ) ); } |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _set_get_convert_size |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
|
|
my $self = shift( @_ ); |
68
|
0
|
|
|
|
|
|
my $field = shift( @_ ); |
69
|
0
|
0
|
|
|
|
|
if( @_ ) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
|
my $num = shift( @_ ); |
72
|
0
|
0
|
|
|
|
|
return( $self->_set_get_number( $field, $num ) ) if( !$self->{use_metric} ); |
73
|
|
|
|
|
|
|
# Helper method from Net::API::Stripe::Generic |
74
|
|
|
|
|
|
|
# If metric option is on, convert the metric value into inch to be compliant with Stripe |
75
|
0
|
|
|
|
|
|
my $new = $self->_convert_measure({ from => 'cm', value => "$num" }); |
76
|
0
|
|
|
|
|
|
return( $self->_set_get_number( $field, $new ) ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
# No argument, just retrieving the value |
79
|
|
|
|
|
|
|
else |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
|
my $val = $self->{ $field }; |
82
|
0
|
0
|
|
|
|
|
return( $val ) if( !$self->{use_metric} ); |
83
|
0
|
|
|
|
|
|
my $new = $self->_convert_measure({ from => 'inch', value => "$val" }); |
84
|
0
|
|
|
|
|
|
require Module::Generic::Number; |
85
|
0
|
|
|
|
|
|
return( Module::Generic::Number->new( $new ) ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _set_get_convert_weight |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
0
|
|
|
my $self = shift( @_ ); |
92
|
0
|
|
|
|
|
|
my $field = shift( @_ ); |
93
|
0
|
0
|
|
|
|
|
if( @_ ) |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
|
my $num = shift( @_ ); |
96
|
0
|
0
|
|
|
|
|
return( $self->_set_get_number( $field, $num ) ) if( !$self->{use_metric} ); |
97
|
|
|
|
|
|
|
# Helper method from Net::API::Stripe::Generic |
98
|
|
|
|
|
|
|
# If metric option is on, convert the metric value into inch to be compliant with Stripe |
99
|
0
|
|
|
|
|
|
my $new = $self->_convert_measure({ from => 'gram', value => "$num" }); |
100
|
0
|
|
|
|
|
|
return( $self->_set_get_number( $field, $new ) ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
# No argument, just retrieving the value |
103
|
|
|
|
|
|
|
else |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
my $val = $self->{ $field }; |
106
|
0
|
0
|
|
|
|
|
return( $val ) if( !$self->{use_metric} ); |
107
|
0
|
|
|
|
|
|
my $new = $self->_convert_measure({ from => 'gram', value => "$val" }); |
108
|
0
|
|
|
|
|
|
require Module::Generic::Number; |
109
|
0
|
|
|
|
|
|
return( Module::Generic::Number->new( $new ) ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=encoding utf8 |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 NAME |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Net::API::Stripe::Product::PackageDimension - A Stripe Product Package Dimension Object |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SYNOPSIS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# In inches |
126
|
|
|
|
|
|
|
my $pkg = $stripe->product->package_dimensions({ |
127
|
|
|
|
|
|
|
height => 6, |
128
|
|
|
|
|
|
|
length => 20, |
129
|
|
|
|
|
|
|
# Ounce |
130
|
|
|
|
|
|
|
weight => 21 |
131
|
|
|
|
|
|
|
width => 12 |
132
|
|
|
|
|
|
|
}); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Then, because we are in EU |
135
|
|
|
|
|
|
|
$pkg->use_metric( 1 ); |
136
|
|
|
|
|
|
|
my $width = $pkg->width; |
137
|
|
|
|
|
|
|
# returns in centimetres: 30.48 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 VERSION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
v0.100.1 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 DESCRIPTION |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The dimensions of this SKU for shipping purposes. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This is instantiated by method B<package_dimensions> in module L<Net::API::Stripe::Product> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 new( %ARG ) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Creates a new L<Net::API::Stripe::Order::SKU::PackageDimensions> object. |
154
|
|
|
|
|
|
|
It may also take an hash like arguments, that also are method of the same name. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 METHODS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 height decimal |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Height, in inches. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 length decimal |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Length, in inches. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 use_metric Boolean |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
By providing a boolean value, you can change the value returned to you. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Stripe uses and requires, unfortunately, the use of C<inch> and C<ounce> although the vast majority of the word uses the metric system. So this feature makes it possible to get the proper value while still sending Stripe the values in the proper measurement system. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
If on, this will convert all values from inch to metric, or ounce to gram or vice versa. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Internally the values will always be in C<inch> and C<ounce>. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
So, after having retrieved a L<Net::API::Stripe::Order::SKU> object from Stripe you could do something like this: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my $sku = $stripe->skus( retrieve => $id ) || die( $stripe->error ); |
179
|
|
|
|
|
|
|
$sku->package_dimensions->use_metric( 1 ); |
180
|
|
|
|
|
|
|
# Width in centimetres |
181
|
|
|
|
|
|
|
my $width = $skup->package_dimensions->width; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 weight decimal |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Weight, in ounces. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 width decimal |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Width, in inches. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 API SAMPLE |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
{ |
194
|
|
|
|
|
|
|
"id": "prod_fake123456789", |
195
|
|
|
|
|
|
|
"object": "product", |
196
|
|
|
|
|
|
|
"active": true, |
197
|
|
|
|
|
|
|
"attributes": [], |
198
|
|
|
|
|
|
|
"caption": null, |
199
|
|
|
|
|
|
|
"created": 1541833574, |
200
|
|
|
|
|
|
|
"deactivate_on": [], |
201
|
|
|
|
|
|
|
"description": null, |
202
|
|
|
|
|
|
|
"images": [], |
203
|
|
|
|
|
|
|
"livemode": false, |
204
|
|
|
|
|
|
|
"metadata": {}, |
205
|
|
|
|
|
|
|
"name": "Provider, Inc investor yearly membership", |
206
|
|
|
|
|
|
|
"package_dimensions": null, |
207
|
|
|
|
|
|
|
"shippable": null, |
208
|
|
|
|
|
|
|
"statement_descriptor": null, |
209
|
|
|
|
|
|
|
"type": "service", |
210
|
|
|
|
|
|
|
"unit_label": null, |
211
|
|
|
|
|
|
|
"updated": 1565089803, |
212
|
|
|
|
|
|
|
"url": null |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 HISTORY |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 v0.1 |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Initial version |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 AUTHOR |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 SEE ALSO |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Stripe API documentation: |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
L<https://stripe.com/docs/api/products/object> |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Copyright (c) 2019-2020 DEGUEST Pte. Ltd. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
You can use, copy, modify and redistribute this package and associated |
236
|
|
|
|
|
|
|
files under the same terms as Perl itself. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |