|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Squareetlabs\AuthorizeNet\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Squareetlabs\AuthorizeNet\AuthorizeNet; |
|
6
|
|
|
use net\authorize\api\controller as AnetControllers; |
|
7
|
|
|
use net\authorize\api\contract\v1 as AnetAPI; |
|
8
|
|
|
|
|
9
|
|
|
class PaymentProfileChargeService extends AuthorizeNet |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Charge a payment profile. |
|
13
|
|
|
* |
|
14
|
|
|
* @param int $cents Amount in cents |
|
15
|
|
|
* @param int $paymentProfileId Payment profile ID |
|
16
|
|
|
* @return AnetAPI\CreateTransactionResponse |
|
17
|
|
|
*/ |
|
18
|
|
|
public function charge(int $cents, int $paymentProfileId): AnetAPI\CreateTransactionResponse |
|
19
|
|
|
{ |
|
20
|
|
|
$amount = $this->convertCentsToDollar($cents); |
|
21
|
|
|
|
|
22
|
|
|
$profileToCharge = new AnetAPI\CustomerProfilePaymentType(); |
|
23
|
|
|
$profileToCharge->setCustomerProfileId($this->user->anet()->getCustomerProfileId()); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$paymentProfile = new AnetAPI\PaymentProfileType(); |
|
26
|
|
|
$paymentProfile->setPaymentProfileId($paymentProfileId); |
|
27
|
|
|
|
|
28
|
|
|
$profileToCharge->setPaymentProfile($paymentProfile); |
|
29
|
|
|
|
|
30
|
|
|
$transactionRequestType = new AnetAPI\TransactionRequestType(); |
|
31
|
|
|
$transactionRequestType->setTransactionType('authCaptureTransaction'); |
|
32
|
|
|
$transactionRequestType->setAmount($amount); |
|
33
|
|
|
$transactionRequestType->setProfile($profileToCharge); |
|
34
|
|
|
|
|
35
|
|
|
$request = new AnetAPI\CreateTransactionRequest(); |
|
36
|
|
|
$request->setMerchantAuthentication($this->getMerchantAuthentication()); |
|
37
|
|
|
$request->setRefId($this->getRefId()); |
|
38
|
|
|
$request->setTransactionRequest($transactionRequestType); |
|
39
|
|
|
|
|
40
|
|
|
$controller = new AnetControllers\CreateTransactionController($request); |
|
41
|
|
|
|
|
42
|
|
|
return $this->execute($controller); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|