line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Braintree::Transaction; |
2
|
|
|
|
|
|
|
$WebService::Braintree::Transaction::VERSION = '0.93'; |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
WebService::Braintree::Transaction |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 PURPOSE |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This class generates and manages transactions. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
351
|
use WebService::Braintree::Transaction::CreatedUsing; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
14
|
1
|
|
|
1
|
|
392
|
use WebService::Braintree::Transaction::EscrowStatus; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
15
|
1
|
|
|
1
|
|
290
|
use WebService::Braintree::Transaction::Source; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
16
|
1
|
|
|
1
|
|
251
|
use WebService::Braintree::Transaction::Status; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
17
|
1
|
|
|
1
|
|
255
|
use WebService::Braintree::Transaction::Type; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
20
|
|
|
|
|
|
|
extends "WebService::Braintree::ResultObject"; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 CLASS METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 sale() |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This takes a hashref of parameters and returns the transaction created. This is |
27
|
|
|
|
|
|
|
a wrapper around L</create()> with the type set to 'sale'. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub sale { |
32
|
0
|
|
|
0
|
1
|
|
my ($class, $params) = @_; |
33
|
0
|
|
|
|
|
|
$class->create($params, 'sale'); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 credit() |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This takes a hashref of parameters and returns the transaction created. This is |
39
|
|
|
|
|
|
|
a wrapper around L</create()> with the type set to 'credit'. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub credit { |
44
|
0
|
|
|
0
|
1
|
|
my ($class, $params) = @_; |
45
|
0
|
|
|
|
|
|
$class->create($params, 'credit'); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 credit() |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This takes a hashref of parameters and a type and returns the transaction |
51
|
|
|
|
|
|
|
created. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
In general, you will not call this method. Instead, call one of the wrappers |
54
|
|
|
|
|
|
|
of this method, such as L</sale()> and L</credit()>. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub create { |
59
|
0
|
|
|
0
|
0
|
|
my ($class, $params, $type) = @_; |
60
|
0
|
|
|
|
|
|
$params->{'type'} = $type; |
61
|
0
|
|
|
|
|
|
$class->gateway->transaction->create($params); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 find() |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This takes an id and returns the transaction (if it exists). |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub find { |
71
|
0
|
|
|
0
|
1
|
|
my ($class, $id) = @_; |
72
|
0
|
|
|
|
|
|
$class->gateway->transaction->find($id); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 clone_transaction() |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This takes an id and a hashref of parameters and clones the transaction (if it |
78
|
|
|
|
|
|
|
exists) with the parameters as overrides. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub clone_transaction { |
83
|
0
|
|
|
0
|
1
|
|
my ($class, $id, $params) = @_; |
84
|
0
|
|
|
|
|
|
$class->gateway->transaction->clone_transaction($id, $params); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 void() |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This takes an id and voids the transaction (if it exists). |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub void { |
94
|
0
|
|
|
0
|
1
|
|
my ($class, $id) = @_; |
95
|
0
|
|
|
|
|
|
$class->gateway->transaction->void($id); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 submit_for_settlement() |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This takes an id and an optional amount and submits the transaction (if it |
101
|
|
|
|
|
|
|
exists) for settlement. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub submit_for_settlement { |
106
|
0
|
|
|
0
|
1
|
|
my ($class, $id, $amount) = @_; |
107
|
0
|
|
|
|
|
|
my $params = {}; |
108
|
0
|
0
|
|
|
|
|
$params->{'amount'} = $amount if $amount; |
109
|
0
|
|
|
|
|
|
$class->gateway->transaction->submit_for_settlement($id, $params); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 refund() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This takes an id and an optional amount and refunds the transaction (if it |
115
|
|
|
|
|
|
|
exists). |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub refund { |
120
|
0
|
|
|
0
|
1
|
|
my ($class, $id, $amount) = @_; |
121
|
0
|
|
|
|
|
|
my $params = {}; |
122
|
0
|
0
|
|
|
|
|
$params->{'amount'} = $amount if $amount; |
123
|
0
|
|
|
|
|
|
$class->gateway->transaction->refund($id, $params); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 hold_in_escrow() |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This takes an id and holds the transaction (if it exists) in escrow. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub hold_in_escrow { |
133
|
0
|
|
|
0
|
1
|
|
my ($class, $id) = @_; |
134
|
0
|
|
|
|
|
|
$class->gateway->transaction->hold_in_escrow($id); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 release_from_escrow() |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This takes an id and releases the transaction (if it exists) from escrow. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub release_from_escrow { |
144
|
0
|
|
|
0
|
1
|
|
my ($class, $id) = @_; |
145
|
0
|
|
|
|
|
|
$class->gateway->transaction->release_from_escrow($id); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 cancel_release() |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This takes an id and cancels the release of the transaction (if it exists). |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub cancel_release { |
155
|
0
|
|
|
0
|
1
|
|
my ($class, $id) = @_; |
156
|
0
|
|
|
|
|
|
$class->gateway->transaction->cancel_release($id); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 search() |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This takes a subref which is used to set the search parameters and returns a |
162
|
|
|
|
|
|
|
transaction object. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Please see L<Searching|WebService::Braintree/SEARCHING> for more information on |
165
|
|
|
|
|
|
|
the subref and how it works. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub search { |
170
|
0
|
|
|
0
|
1
|
|
my ($class, $block) = @_; |
171
|
0
|
|
|
|
|
|
$class->gateway->transaction->search($block); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 all() |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This returns all the transactions. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub all { |
181
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
182
|
0
|
|
|
|
|
|
$class->gateway->transaction->all; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub gateway { |
186
|
0
|
|
|
0
|
0
|
|
WebService::Braintree->configuration->gateway; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
In addition to the methods provided by the keys returned from Braintree, this |
192
|
|
|
|
|
|
|
class provides the following methods: |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 disbursement_details() |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This returns the disbursement details of this transaction (if they exist). It |
197
|
|
|
|
|
|
|
will be a L<WebService::Braintree::DisbursementDetails> object. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
has disbursement_details => (is => 'rw'); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 paypal_details() |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This returns the PayPal details of this transaction (if they exist). It |
206
|
|
|
|
|
|
|
will be a L<WebService::Braintree::PayPalDetails> object. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
has paypal_details => (is => 'rw'); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 subscription() |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This returns the related subscription of this transaction (if they exist). It |
215
|
|
|
|
|
|
|
will be a L<WebService::Braintree::Subscription> object. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
has subscription => (is => 'rw'); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub BUILD { |
222
|
0
|
|
|
0
|
0
|
|
my ($self, $attributes) = @_; |
223
|
0
|
|
|
|
|
|
my $sub_objects = { |
224
|
|
|
|
|
|
|
disputes => 'WebService::Braintree::Dispute', |
225
|
|
|
|
|
|
|
}; |
226
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
$self->subscription(WebService::Braintree::Subscription->new($attributes->{subscription})) if ref($attributes->{subscription}) eq 'HASH'; |
228
|
0
|
|
|
|
|
|
delete($attributes->{subscription}); |
229
|
|
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
|
$self->disbursement_details(WebService::Braintree::DisbursementDetails->new($attributes->{disbursement_details})) if ref($attributes->{disbursement_details}) eq 'HASH'; |
231
|
0
|
|
|
|
|
|
delete($attributes->{disbursement_details}); |
232
|
|
|
|
|
|
|
|
233
|
0
|
0
|
|
|
|
|
$self->paypal_details(WebService::Braintree::PayPalDetails->new($attributes->{paypal})) if ref($attributes->{paypal}) eq 'HASH'; |
234
|
0
|
|
|
|
|
|
delete($attributes->{paypal}); |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
$self->setup_sub_objects($self, $attributes, $sub_objects); |
237
|
0
|
|
|
|
|
|
$self->set_attributes_from_hash($self, $attributes); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 is_disbursed() |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This returns whether or not the disbursement details of this transaction are |
243
|
|
|
|
|
|
|
valid. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub is_disbursed { |
248
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
249
|
0
|
|
|
|
|
|
$self->disbursement_details->is_valid(); |
250
|
|
|
|
|
|
|
}; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1; |
255
|
|
|
|
|
|
|
__END__ |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 TODO |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over 4 |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item Need to document the keys and values that are returned |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item Need to document the required and optional input parameters |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item Need to document the possible errors/exceptions |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=back |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |