PaymentProfileChargeService   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 34
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A charge() 0 25 1
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());
0 ignored issues
show
Bug introduced by
It seems like $this->user->anet()->getCustomerProfileId() can also be of type Illuminate\Database\Eloquent\Builder and Illuminate\Database\Eloq...gHasThroughRelationship; however, parameter $customerProfileId of net\authorize\api\contra...:setCustomerProfileId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $profileToCharge->setCustomerProfileId(/** @scrutinizer ignore-type */ $this->user->anet()->getCustomerProfileId());
Loading history...
Bug introduced by
The method anet() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $profileToCharge->setCustomerProfileId($this->user->/** @scrutinizer ignore-call */ anet()->getCustomerProfileId());
Loading history...
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