| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2013 Digital River, Inc. |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
4
|
|
|
|
|
|
|
# you may not use this file except in compliance with the License. |
|
5
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
10
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
11
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
|
13
|
|
|
|
|
|
|
# limitations under the License. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Net::MyCommerce::API::Resource::Carts; |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
33
|
|
|
18
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
27
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
5
|
use base qw( Net::MyCommerce::API::Resource ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
815
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Net::MyCommerce::API::Resource::Carts |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 VERSION |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
version 1.0.1 |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SCHEMA |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/14-schemas-cart |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new ($args) |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Subclass Net::MyCommerce::API::Resource |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
|
47
|
0
|
|
|
0
|
1
|
|
my ($pkg, %args) = @_; |
|
48
|
0
|
|
|
|
|
|
return $pkg->SUPER::new( %args, scope=>'carts' ); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 request (%opts) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Subclass Net::MyCommerce::API::Resource::request |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub request { |
|
58
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
59
|
0
|
|
0
|
|
|
|
$opts{params} ||= {}; |
|
60
|
0
|
|
0
|
|
|
|
$opts{params}->{language} ||= 'en_US'; |
|
61
|
0
|
|
|
|
|
|
return $self->SUPER::request(%opts); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 create_cart |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Create a new cart |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Examples: |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/7-example-create-cart-simple-one-product |
|
71
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/21-example-create-cart-fill-in-shopper-information |
|
72
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/18-example-create-cart-affiliate |
|
73
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/35-example-create-shopping-cart-custom-fields |
|
74
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/36-example-create-shopping-cart-offers |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub create_cart { |
|
79
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
80
|
0
|
|
0
|
|
|
|
$opts{item} ||= {}; |
|
81
|
0
|
|
|
|
|
|
return $self->request( |
|
82
|
|
|
|
|
|
|
method => 'POST', |
|
83
|
|
|
|
|
|
|
path => '/carts', |
|
84
|
|
|
|
|
|
|
params => $opts{params}, |
|
85
|
|
|
|
|
|
|
data => { |
|
86
|
|
|
|
|
|
|
items => [ |
|
87
|
|
|
|
|
|
|
{ |
|
88
|
|
|
|
|
|
|
product_id => $opts{item}->{product_id}, |
|
89
|
|
|
|
|
|
|
quantity => $opts{item}->{quantity}, |
|
90
|
|
|
|
|
|
|
}, |
|
91
|
|
|
|
|
|
|
] |
|
92
|
|
|
|
|
|
|
}, |
|
93
|
|
|
|
|
|
|
); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 add_item |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Add a new item to an existing shopping cart |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub add_item { |
|
103
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
104
|
0
|
|
0
|
|
|
|
$opts{item} ||= {}; |
|
105
|
0
|
0
|
|
|
|
|
return $self->request( |
|
106
|
|
|
|
|
|
|
method => 'POST', |
|
107
|
|
|
|
|
|
|
path => $opts{cart_id} ? [ '/carts', $opts{cart_id} ] : '/carts', |
|
108
|
|
|
|
|
|
|
params => $opts{params}, |
|
109
|
|
|
|
|
|
|
data => { |
|
110
|
|
|
|
|
|
|
items => [ |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
|
|
|
|
|
|
product_id => $opts{item}->{product_id}, |
|
113
|
|
|
|
|
|
|
quantity => $opts{item}->{quantity}, |
|
114
|
|
|
|
|
|
|
custom_fields => $opts{item}->{custom_fields}, |
|
115
|
|
|
|
|
|
|
offer_id => $opts{item}->{offer_id}, |
|
116
|
|
|
|
|
|
|
}, |
|
117
|
|
|
|
|
|
|
] |
|
118
|
|
|
|
|
|
|
}, |
|
119
|
|
|
|
|
|
|
); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 update_items |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Add/modify one or more items in an existing shopping cart |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Examples: |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/20-example-update-cart-set-quantity |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub update_items { |
|
133
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
134
|
0
|
|
|
|
|
|
return $self->request( |
|
135
|
|
|
|
|
|
|
method => 'POST', |
|
136
|
|
|
|
|
|
|
path => [ '/carts', $opts{cart_id} ], |
|
137
|
|
|
|
|
|
|
params => $opts{params}, |
|
138
|
|
|
|
|
|
|
data => { |
|
139
|
|
|
|
|
|
|
items => $opts{items}, |
|
140
|
|
|
|
|
|
|
coupon_code => $opts{coupon_code}, |
|
141
|
|
|
|
|
|
|
}, |
|
142
|
|
|
|
|
|
|
); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 update_cart |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Update shopping cart: one or more items, billing/shipping address, and/or coupon |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub update_cart { |
|
152
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
153
|
0
|
0
|
|
|
|
|
return $self->request( |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
method => 'POST', |
|
155
|
|
|
|
|
|
|
path => [ '/carts', $opts{cart_id} ], |
|
156
|
|
|
|
|
|
|
params => $opts{params}, |
|
157
|
|
|
|
|
|
|
data => { |
|
158
|
|
|
|
|
|
|
( $opts{billing_address} ? (billing_address => $opts{billing_address}) : () ), |
|
159
|
|
|
|
|
|
|
( $opts{shipping_address} ? (shipping_address => $opts{shipping_address}) : () ), |
|
160
|
|
|
|
|
|
|
( $opts{items} ? (items => $opts{items}) : () ), |
|
161
|
|
|
|
|
|
|
( $opts{coupon_code} ? (coupon_code => $opts{coupon_code}) : () ), |
|
162
|
|
|
|
|
|
|
}, |
|
163
|
|
|
|
|
|
|
); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 remove_item |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Remove an item from an existing shopping cart |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub remove_item { |
|
173
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
174
|
0
|
|
|
|
|
|
return $self->request( |
|
175
|
|
|
|
|
|
|
method => 'DELETE', |
|
176
|
|
|
|
|
|
|
path => [ '/carts', $opts{cart_id}, 'items', $opts{item_id} ], |
|
177
|
|
|
|
|
|
|
); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 get_cart |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Retrieve an existing shopping cart |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Examples: |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/19-example-get-cart |
|
187
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/38-example-get-shopping-cart-select-or-hide-fields |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub get_cart { |
|
192
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
193
|
0
|
|
|
|
|
|
my ($error, $result) = $self->request( |
|
194
|
|
|
|
|
|
|
method => 'GET', |
|
195
|
|
|
|
|
|
|
path => [ '/carts', $opts{cart_id} ], |
|
196
|
|
|
|
|
|
|
params => $opts{params}, |
|
197
|
|
|
|
|
|
|
); |
|
198
|
0
|
0
|
|
|
|
|
return ($error, $result) if $error; |
|
199
|
0
|
0
|
0
|
|
|
|
if (ref($result) eq 'HASH' && |
|
|
|
|
0
|
|
|
|
|
|
200
|
|
|
|
|
|
|
ref($result->{content}) eq 'HASH' && |
|
201
|
|
|
|
|
|
|
ref($result->{content}{items}) eq 'ARRAY') { |
|
202
|
0
|
|
|
|
|
|
foreach my $item (@{$result->{content}{items}}) { |
|
|
0
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
my $p = $item->{pricing}; |
|
204
|
0
|
|
0
|
|
|
|
my $q = $item->{quantity} || 1; |
|
205
|
0
|
|
|
|
|
|
$p->{non_discount_total} = sprintf("%.2f", $p->{total} + $p->{discount}); |
|
206
|
0
|
|
|
|
|
|
$p->{discount_unit_price} = sprintf("%.2f", $p->{unit_price} - $p->{discount}/$q); |
|
207
|
|
|
|
|
|
|
} |
|
208
|
0
|
|
|
|
|
|
my $discount = $result->{content}{pricing}{discount}; |
|
209
|
0
|
0
|
|
|
|
|
$result->{content}{pricing}{discount} = sprintf("%.2f",$discount) if $discount; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
0
|
|
|
|
|
|
return ($error, $result); |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 get_item |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Retrieve a single item from an existing shopping cart |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Examples: |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
http://help.mycommerce.com/index.php/mycommerce-apis/cart-resource/19-example-get-cart |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub get_item { |
|
225
|
0
|
|
|
0
|
1
|
|
my ($self, %opts) = @_; |
|
226
|
0
|
|
|
|
|
|
return $self->request( |
|
227
|
|
|
|
|
|
|
method => 'GET', |
|
228
|
|
|
|
|
|
|
path => [ '/carts', $opts{cart_id}, 'items', $opts{item_id} ], |
|
229
|
|
|
|
|
|
|
params => $opts{params}, |
|
230
|
|
|
|
|
|
|
); |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |