This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Agreement.php
647 lines (602 loc) · 20 KB
/
Agreement.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
<?php
namespace PayPal\Api;
use PayPal\Common\PayPalResourceModel;
use PayPal\Core\PayPalConstants;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PayPalRestCall;
use PayPal\Validation\ArgumentValidator;
/**
* Class Agreement
*
* A resource representing an agreement.
*
* @package PayPal\Api
*
* @property string id
* @property string state
* @property string name
* @property string description
* @property string start_date
* @property \PayPal\Api\Payer payer
* @property \PayPal\Api\Address shipping_address
* @property \PayPal\Api\MerchantPreferences override_merchant_preferences
* @property \PayPal\Api\OverrideChargeModel[] override_charge_models
* @property \PayPal\Api\Plan plan
* @property string create_time
* @property string update_time
* @property \PayPal\Api\AgreementDetails agreement_details
*/
class Agreement extends PayPalResourceModel
{
/**
* Identifier of the agreement.
*
* @param string $id
*
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Identifier of the agreement.
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* State of the agreement.
*
* @param string $state
*
* @return $this
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* State of the agreement.
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* Name of the agreement.
*
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Name of the agreement.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Description of the agreement.
*
* @param string $description
*
* @return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Description of the agreement.
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @param string $start_date
*
* @return $this
*/
public function setStartDate($start_date)
{
$this->start_date = $start_date;
return $this;
}
/**
* Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @return string
*/
public function getStartDate()
{
return $this->start_date;
}
/**
* Details of the buyer who is enrolling in this agreement. This information is gathered from execution of the approval URL.
*
* @param \PayPal\Api\Payer $payer
*
* @return $this
*/
public function setPayer($payer)
{
$this->payer = $payer;
return $this;
}
/**
* Details of the buyer who is enrolling in this agreement. This information is gathered from execution of the approval URL.
*
* @return \PayPal\Api\Payer
*/
public function getPayer()
{
return $this->payer;
}
/**
* Shipping address object of the agreement, which should be provided if it is different from the default address.
*
* @param \PayPal\Api\Address $shipping_address
*
* @return $this
*/
public function setShippingAddress($shipping_address)
{
$this->shipping_address = $shipping_address;
return $this;
}
/**
* Shipping address object of the agreement, which should be provided if it is different from the default address.
*
* @return \PayPal\Api\Address
*/
public function getShippingAddress()
{
return $this->shipping_address;
}
/**
* Default merchant preferences from the billing plan are used, unless override preferences are provided here.
*
* @param \PayPal\Api\MerchantPreferences $override_merchant_preferences
*
* @return $this
*/
public function setOverrideMerchantPreferences($override_merchant_preferences)
{
$this->override_merchant_preferences = $override_merchant_preferences;
return $this;
}
/**
* Default merchant preferences from the billing plan are used, unless override preferences are provided here.
*
* @return \PayPal\Api\MerchantPreferences
*/
public function getOverrideMerchantPreferences()
{
return $this->override_merchant_preferences;
}
/**
* Array of override_charge_model for this agreement if needed to change the default models from the billing plan.
*
* @param \PayPal\Api\OverrideChargeModel[] $override_charge_models
*
* @return $this
*/
public function setOverrideChargeModels($override_charge_models)
{
$this->override_charge_models = $override_charge_models;
return $this;
}
/**
* Array of override_charge_model for this agreement if needed to change the default models from the billing plan.
*
* @return \PayPal\Api\OverrideChargeModel[]
*/
public function getOverrideChargeModels()
{
return $this->override_charge_models;
}
/**
* Append OverrideChargeModels to the list.
*
* @param \PayPal\Api\OverrideChargeModel $overrideChargeModel
* @return $this
*/
public function addOverrideChargeModel($overrideChargeModel)
{
if (!$this->getOverrideChargeModels()) {
return $this->setOverrideChargeModels(array($overrideChargeModel));
} else {
return $this->setOverrideChargeModels(
array_merge($this->getOverrideChargeModels(), array($overrideChargeModel))
);
}
}
/**
* Remove OverrideChargeModels from the list.
*
* @param \PayPal\Api\OverrideChargeModel $overrideChargeModel
* @return $this
*/
public function removeOverrideChargeModel($overrideChargeModel)
{
return $this->setOverrideChargeModels(
array_diff($this->getOverrideChargeModels(), array($overrideChargeModel))
);
}
/**
* Plan details for this agreement.
*
* @param \PayPal\Api\Plan $plan
*
* @return $this
*/
public function setPlan($plan)
{
$this->plan = $plan;
return $this;
}
/**
* Plan details for this agreement.
*
* @return \PayPal\Api\Plan
*/
public function getPlan()
{
return $this->plan;
}
/**
* Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @param string $create_time
*
* @return $this
*/
public function setCreateTime($create_time)
{
$this->create_time = $create_time;
return $this;
}
/**
* Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @return string
*/
public function getCreateTime()
{
return $this->create_time;
}
/**
* Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @param string $update_time
*
* @return $this
*/
public function setUpdateTime($update_time)
{
$this->update_time = $update_time;
return $this;
}
/**
* Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
*
* @return string
*/
public function getUpdateTime()
{
return $this->update_time;
}
/**
* Agreement Details
*
* @param \PayPal\Api\AgreementDetails $agreement_details
*
* @return $this
*/
public function setAgreementDetails($agreement_details)
{
$this->agreement_details = $agreement_details;
return $this;
}
/**
* Agreement Details
*
* @return \PayPal\Api\AgreementDetails
*/
public function getAgreementDetails()
{
return $this->agreement_details;
}
/**
* Get Approval Link
*
* @return null|string
*/
public function getApprovalLink()
{
return $this->getLink(PayPalConstants::APPROVAL_URL);
}
/**
* Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON.
*
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Agreement
*/
public function create($apiContext = null, $restCall = null)
{
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/payments/billing-agreements/",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
/**
* Execute a billing agreement after buyer approval by passing the payment token to the request URI.
*
* @param $paymentToken
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Agreement
*/
public function execute($paymentToken, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($paymentToken, 'paymentToken');
$payLoad = "";
$json = self::executeCall(
"/v1/payments/billing-agreements/$paymentToken/agreement-execute",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
/**
* Retrieve details for a particular billing agreement by passing the ID of the agreement to the request URI.
*
* @param string $agreementId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return Agreement
*/
public static function get($agreementId, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($agreementId, 'agreementId');
$payLoad = "";
$json = self::executeCall(
"/v1/payments/billing-agreements/$agreementId",
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new Agreement();
$ret->fromJson($json);
return $ret;
}
/**
* Update details of a billing agreement, such as the description, shipping address, and start date, by passing the ID of the agreement to the request URI.
*
* @param PatchRequest $patchRequest
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function update($patchRequest, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($patchRequest, 'patchRequest');
$payLoad = $patchRequest->toJSON();
self::executeCall(
"/v1/payments/billing-agreements/{$this->getId()}",
"PATCH",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Suspend a particular billing agreement by passing the ID of the agreement to the request URI.
*
* @param AgreementStateDescriptor $agreementStateDescriptor
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function suspend($agreementStateDescriptor, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor');
$payLoad = $agreementStateDescriptor->toJSON();
self::executeCall(
"/v1/payments/billing-agreements/{$this->getId()}/suspend",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Reactivate a suspended billing agreement by passing the ID of the agreement to the appropriate URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.
*
* @param AgreementStateDescriptor $agreementStateDescriptor
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function reActivate($agreementStateDescriptor, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor');
$payLoad = $agreementStateDescriptor->toJSON();
self::executeCall(
"/v1/payments/billing-agreements/{$this->getId()}/re-activate",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Cancel a billing agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.
*
* @param AgreementStateDescriptor $agreementStateDescriptor
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function cancel($agreementStateDescriptor, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor');
$payLoad = $agreementStateDescriptor->toJSON();
self::executeCall(
"/v1/payments/billing-agreements/{$this->getId()}/cancel",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Bill an outstanding amount for an agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.
*
* @param AgreementStateDescriptor $agreementStateDescriptor
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function billBalance($agreementStateDescriptor, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor');
$payLoad = $agreementStateDescriptor->toJSON();
self::executeCall(
"/v1/payments/billing-agreements/{$this->getId()}/bill-balance",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* Set the balance for an agreement by passing the ID of the agreement to the request URI. In addition, pass a common_currency object in the request JSON that specifies the currency type and value of the balance.
*
* @param Currency $currency
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return bool
*/
public function setBalance($currency, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
ArgumentValidator::validate($currency, 'currency');
$payLoad = $currency->toJSON();
self::executeCall(
"/v1/payments/billing-agreements/{$this->getId()}/set-balance",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
return true;
}
/**
* List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.
*
* @deprecated Please use searchTransactions Instead
* @param string $agreementId
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return AgreementTransactions
*/
public static function transactions($agreementId, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($agreementId, 'agreementId');
$payLoad = "";
$json = self::executeCall(
"/v1/payments/billing-agreements/$agreementId/transactions",
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new AgreementTransactions();
$ret->fromJson($json);
return $ret;
}
/**
* List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.
*
* @param string $agreementId
* @param array $params Parameters for search string. Options: start_date, and end_date
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return AgreementTransactions
*/
public static function searchTransactions($agreementId, $params = array(), $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($agreementId, 'agreementId');
ArgumentValidator::validate($params, 'params');
$allowedParams = array(
'start_date' => 1,
'end_date' => 1,
);
$payLoad = "";
$json = self::executeCall(
"/v1/payments/billing-agreements/$agreementId/transactions?" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET",
$payLoad,
null,
$apiContext,
$restCall
);
$ret = new AgreementTransactions();
$ret->fromJson($json);
return $ret;
}
}