Failed Conditions
Push — develop ( 93b791...a66526 )
by Reüel
05:23 queued 12s
created

Gateway::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 12
ccs 0
cts 7
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\TargetPay;
4
5
use Pronamic\WordPress\Pay\Banks\BankAccountDetails;
6
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
7
use Pronamic\WordPress\Pay\Core\PaymentMethods;
8
use Pronamic\WordPress\Pay\Payments\Payment;
9
10
/**
11
 * Title: TargetPay gateway
12
 * Description:
13
 * Copyright: 2005-2021 Pronamic
14
 * Company: Pronamic
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.0.3
18
 * @since   1.0.0
19
 */
20
class Gateway extends Core_Gateway {
21
	/**
22
	 * Client.
23
	 *
24
	 * @var Client
25
	 */
26
	protected $client;
27
28
	/**
29
	 * Constructs and initializes an TargetPay gateway
30
	 *
31
	 * @param Config $config Config.
32
	 */
33
	public function __construct( Config $config ) {
34
		parent::__construct( $config );
35
36
		$this->set_method( self::METHOD_HTTP_REDIRECT );
37
38
		// Supported features.
39
		$this->supports = array(
40
			'payment_status_request',
41
		);
42
43
		// Client.
44
		$this->client = new Client();
45
	}
46
47
	/**
48
	 * Get issuers
49
	 *
50
	 * @see Pronamic_WP_Pay_Gateway::get_issuers()
51
	 */
52
	public function get_issuers() {
53
		$groups = array();
54
55
		$result = $this->client->get_issuers();
56
57
		if ( $result ) {
58
			$groups[] = array(
59
				'options' => $result,
60
			);
61
		}
62
63
		return $groups;
64
	}
65
66
	/**
67
	 * Get supported payment methods
68
	 *
69
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
70
	 */
71
	public function get_supported_payment_methods() {
72
		return array(
73
			PaymentMethods::IDEAL,
74
		);
75
	}
76
77
	/**
78
	 * Start
79
	 *
80
	 * @see Core_Gateway::start()
81
	 *
82
	 * @param Payment $payment Payment.
83
	 */
84
	public function start( Payment $payment ) {
85
		$parameters                    = new IDealStartParameters();
86
		$parameters->rtlo              = $this->config->layoutcode;
87
		$parameters->bank              = $payment->get_issuer();
88
		$parameters->description       = $payment->get_description();
89
		$parameters->amount            = $payment->get_total_amount()->get_cents();
0 ignored issues
show
Deprecated Code introduced by
The function Pronamic\WordPress\Money\Money::get_cents() has been deprecated: 1.2.2 Use `Money::get_minor_units()` instead. ( Ignorable by Annotation )

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

89
		$parameters->amount            = /** @scrutinizer ignore-deprecated */ $payment->get_total_amount()->get_cents();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
90
		$parameters->return_url        = $payment->get_return_url();
91
		$parameters->report_url        = $payment->get_return_url();
92
		$parameters->cinfo_in_callback = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $cinfo_in_callback was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
93
94
		$result = $this->client->start_transaction( $parameters );
95
96
		if ( $result ) {
0 ignored issues
show
introduced by
$result is of type stdClass, thus it always evaluated to true.
Loading history...
97
			$payment->set_action_url( $result->url );
98
			$payment->set_transaction_id( $result->transaction_id );
99
		}
100
	}
101
102
	/**
103
	 * Update status of the specified payment
104
	 *
105
	 * @param Payment $payment Payment.
106
	 */
107
	public function update_status( Payment $payment ) {
108
		// Get transaction status.
109
		$status = $this->client->check_status(
110
			$this->config->layoutcode,
111
			$payment->get_transaction_id(),
112
			false,
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $once of Pronamic\WordPress\Pay\G...\Client::check_status(). ( Ignorable by Annotation )

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

112
			/** @scrutinizer ignore-type */ false,
Loading history...
113
			self::MODE_TEST === $this->config->mode
114
		);
115
116
		if ( ! $status ) {
0 ignored issues
show
introduced by
$status is of type Pronamic\WordPress\Pay\Gateways\TargetPay\Status, thus it always evaluated to true.
Loading history...
117
			return;
118
		}
119
120
		// Update payment status.
121
		$payment->set_status( Statuses::transform( $status->code ) );
122
123
		// Set payment consumer details.
124
		if ( Statuses::OK === $status->code ) {
125
			$consumer_bank_details = $payment->get_consumer_bank_details();
126
127
			if ( null === $consumer_bank_details ) {
128
				$consumer_bank_details = new BankAccountDetails();
129
130
				$payment->set_consumer_bank_details( $consumer_bank_details );
131
			}
132
133
			$consumer_bank_details->set_name( $status->account_name );
134
			$consumer_bank_details->set_account_number( $status->account_number );
135
			$consumer_bank_details->set_city( $status->account_city );
136
		}
137
	}
138
}
139