|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Squareetlabs\AuthorizeNet; |
|
4
|
|
|
|
|
5
|
|
|
use Squareetlabs\AuthorizeNet\Models\UserGatewayProfile; |
|
6
|
|
|
use Squareetlabs\AuthorizeNet\Models\UserPaymentProfile; |
|
7
|
|
|
use Squareetlabs\AuthorizeNet\Services\CardService; |
|
8
|
|
|
use Squareetlabs\AuthorizeNet\Services\CustomerProfileService; |
|
9
|
|
|
use Squareetlabs\AuthorizeNet\Services\PaymentProfileChargeService; |
|
10
|
|
|
use Squareetlabs\AuthorizeNet\Services\PaymentProfileRefundService; |
|
11
|
|
|
use Squareetlabs\AuthorizeNet\Services\PaymentProfileService; |
|
12
|
|
|
use Squareetlabs\AuthorizeNet\Services\SubscriptionService; |
|
13
|
|
|
use Squareetlabs\AuthorizeNet\Services\TransactionService; |
|
14
|
|
|
use Illuminate\Contracts\Auth\Authenticatable; |
|
15
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
16
|
|
|
use Illuminate\Support\Collection; |
|
17
|
|
|
use net\authorize\api\contract\v1\CreateTransactionResponse; |
|
18
|
|
|
|
|
19
|
|
|
class ANet |
|
20
|
|
|
{ |
|
21
|
|
|
public Authenticatable|Model $user; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* ANet constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param Authenticatable|Model $user |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(Authenticatable|Model $user) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->user = $user; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create customer profile on authorize.net and store payment profile id in the system. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \net\authorize\api\contract\v1\CreateCustomerProfileResponse |
|
37
|
|
|
* @throws \Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public function createCustomerProfile() |
|
40
|
|
|
{ |
|
41
|
|
|
return (new CustomerProfileService($this->user))->create(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the customer profile ID from the database. |
|
46
|
|
|
* |
|
47
|
|
|
* @return string|null |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getCustomerProfileId(): ?string |
|
50
|
|
|
{ |
|
51
|
|
|
$profile = UserGatewayProfile::where('user_id', $this->user->id)->first(); |
|
52
|
|
|
|
|
53
|
|
|
return $profile?->profile_id; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Create a payment profile for the user. |
|
58
|
|
|
* |
|
59
|
|
|
* @param array<string, string> $opaqueData |
|
60
|
|
|
* @param array<string, mixed> $source |
|
61
|
|
|
* @return \net\authorize\api\contract\v1\CreateCustomerPaymentProfileResponse |
|
62
|
|
|
*/ |
|
63
|
|
|
public function createPaymentProfile(array $opaqueData, array $source) |
|
64
|
|
|
{ |
|
65
|
|
|
return (new PaymentProfileService($this->user))->create($opaqueData, $source); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get all payment profile IDs for the user. |
|
70
|
|
|
* |
|
71
|
|
|
* @return Collection<int, string> |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getPaymentProfiles(): Collection |
|
74
|
|
|
{ |
|
75
|
|
|
return UserPaymentProfile::where('user_id', $this->user->id) |
|
76
|
|
|
->pluck('payment_profile_id'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Charge a payment profile. |
|
81
|
|
|
* |
|
82
|
|
|
* @param int $cents Amount in cents |
|
83
|
|
|
* @param int $paymentProfileId Payment profile ID |
|
84
|
|
|
* @return \net\authorize\api\contract\v1\CreateTransactionResponse |
|
85
|
|
|
*/ |
|
86
|
|
|
public function charge(int $cents, int $paymentProfileId) |
|
87
|
|
|
{ |
|
88
|
|
|
return (new PaymentProfileChargeService($this->user))->charge($cents, $paymentProfileId); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Refund a transaction. |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $cents Amount in cents |
|
95
|
|
|
* @param string $refTransId Reference transaction ID |
|
96
|
|
|
* @param int $paymentProfileId Payment profile ID |
|
97
|
|
|
* @return \net\authorize\api\contract\v1\CreateTransactionResponse |
|
98
|
|
|
*/ |
|
99
|
|
|
public function refund(int $cents, string $refTransId, int $paymentProfileId) |
|
100
|
|
|
{ |
|
101
|
|
|
return (new PaymentProfileRefundService($this->user))->handle($cents, $refTransId, $paymentProfileId); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Get all payment methods for the user. |
|
106
|
|
|
* |
|
107
|
|
|
* @return Collection<int, UserPaymentProfile> |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getPaymentMethods(): Collection |
|
110
|
|
|
{ |
|
111
|
|
|
return UserPaymentProfile::where('user_id', $this->user->id)->get(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get only card payment profiles. |
|
116
|
|
|
* |
|
117
|
|
|
* @return Collection<int, UserPaymentProfile> |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getPaymentCardProfiles(): Collection |
|
120
|
|
|
{ |
|
121
|
|
|
return UserPaymentProfile::where('user_id', $this->user->id) |
|
122
|
|
|
->cards() |
|
123
|
|
|
->get(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get only bank payment profiles. |
|
128
|
|
|
* |
|
129
|
|
|
* @return Collection<int, UserPaymentProfile> |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getPaymentBankProfiles(): Collection |
|
132
|
|
|
{ |
|
133
|
|
|
return UserPaymentProfile::where('user_id', $this->user->id) |
|
134
|
|
|
->banks() |
|
135
|
|
|
->get(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Get transaction class instance for transaction-related queries. |
|
140
|
|
|
* |
|
141
|
|
|
* Note: This method requires a CreateTransactionResponse from a previous transaction. |
|
142
|
|
|
* Use this after creating a transaction to work with the response. |
|
143
|
|
|
* |
|
144
|
|
|
* @param CreateTransactionResponse $transactionResponse |
|
145
|
|
|
* @return TransactionService |
|
146
|
|
|
*/ |
|
147
|
|
|
public function transactions(CreateTransactionResponse $transactionResponse): TransactionService |
|
148
|
|
|
{ |
|
149
|
|
|
return new TransactionService($this->user, $transactionResponse); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Get card transaction instance. |
|
155
|
|
|
* |
|
156
|
|
|
* @return CardService |
|
157
|
|
|
*/ |
|
158
|
|
|
public function card(): CardService |
|
159
|
|
|
{ |
|
160
|
|
|
return new CardService($this->user); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Get subscription instance (alias). |
|
165
|
|
|
* |
|
166
|
|
|
* @return Subscription |
|
|
|
|
|
|
167
|
|
|
*/ |
|
168
|
|
|
public function subs(): SubscriptionService |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->subscription(); |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Get subscription instance (alias). |
|
175
|
|
|
* |
|
176
|
|
|
* @return SubscriptionService |
|
177
|
|
|
*/ |
|
178
|
|
|
public function recurring(): SubscriptionService |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->subscription(); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Get subscription instance. |
|
185
|
|
|
* |
|
186
|
|
|
* @return SubscriptionService |
|
187
|
|
|
*/ |
|
188
|
|
|
public function subscription(): SubscriptionService |
|
189
|
|
|
{ |
|
190
|
|
|
return new SubscriptionService($this->user); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths