|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
|
|
7
|
|
|
trait RecurringProfiles |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Create recurring subscription on custom frequency basis. |
|
11
|
|
|
* The billing frequency is in months, i.e: if you want a monthly subscription, then your billing frequency would be 1. |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $token |
|
14
|
|
|
* @param float $amount |
|
15
|
|
|
* @param string $description |
|
16
|
|
|
* @param int $billingFrequency |
|
17
|
|
|
* @param int $trialDays |
|
18
|
|
|
* |
|
19
|
|
|
* @return array |
|
20
|
|
|
*/ |
|
21
|
|
|
public function createCustomSubscription($token, $amount, $description, $billingFrequency, $trialDays = null) |
|
22
|
|
|
{ |
|
23
|
|
|
$data = [ |
|
24
|
|
|
'PROFILESTARTDATE' => Carbon::now()->toAtomString(), |
|
25
|
|
|
'DESC' => $description, |
|
26
|
|
|
'BILLINGPERIOD' => 'Month', |
|
27
|
|
|
'BILLINGFREQUENCY' => $billingFrequency, |
|
28
|
|
|
'AMT' => $amount, |
|
29
|
|
|
'CURRENCYCODE' => $this->currency, |
|
|
|
|
|
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
if (!is_null($trialDays) && is_numeric($trialDays)) { |
|
33
|
|
|
$data['TRIALBILLINGPERIOD'] = 'Day'; |
|
34
|
|
|
$data['TRIALTOTALBILLINGCYCLES'] = $trialDays; |
|
35
|
|
|
$data['TRIALBILLINGFREQUENCY'] = 1; |
|
36
|
|
|
$data['TRIALAMT'] = 0; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $this->createRecurringPaymentsProfile($data, $token); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Create recurring subscription on monthly basis. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $token |
|
46
|
|
|
* @param float $amount |
|
47
|
|
|
* @param string $description |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
public function createMonthlySubscription($token, $amount, $description) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$data = [ |
|
54
|
|
|
'PROFILESTARTDATE' => Carbon::now()->toAtomString(), |
|
55
|
|
|
'DESC' => $description, |
|
56
|
|
|
'BILLINGPERIOD' => 'Month', |
|
57
|
|
|
'BILLINGFREQUENCY' => 1, |
|
58
|
|
|
'AMT' => $amount, |
|
59
|
|
|
'CURRENCYCODE' => $this->currency, |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
return $this->createRecurringPaymentsProfile($data, $token); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Create recurring subscription on yearly basis. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $token |
|
69
|
|
|
* @param float $amount |
|
70
|
|
|
* @param string $description |
|
71
|
|
|
* |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function createYearlySubscription($token, $amount, $description) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$data = [ |
|
77
|
|
|
'PROFILESTARTDATE' => Carbon::now()->toAtomString(), |
|
78
|
|
|
'DESC' => $description, |
|
79
|
|
|
'BILLINGPERIOD' => 'Year', |
|
80
|
|
|
'BILLINGFREQUENCY' => 1, |
|
81
|
|
|
'AMT' => $amount, |
|
82
|
|
|
'CURRENCYCODE' => $this->currency, |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
return $this->createRecurringPaymentsProfile($data, $token); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: