Failed Conditions
Push — develop ( 2a17fb...cb0c7e )
by Reüel
07:36
created

Gateway   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 39
dl 0
loc 108
ccs 0
cts 53
cp 0
rs 10
c 7
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get_supported_payment_methods() 0 3 1
A __construct() 0 12 1
A get_issuers() 0 12 2
A start() 0 15 2
A update_status() 0 21 3
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\TargetPay;
4
5
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
6
use Pronamic\WordPress\Pay\Core\PaymentMethods;
7
use Pronamic\WordPress\Pay\Payments\Payment;
8
9
/**
10
 * Title: TargetPay gateway
11
 * Description:
12
 * Copyright: 2005-2020 Pronamic
13
 * Company: Pronamic
14
 *
15
 * @author  Remco Tolsma
16
 * @version 2.0.3
17
 * @since   1.0.0
18
 */
19
class Gateway extends Core_Gateway {
20
	/**
21
	 * Client.
22
	 *
23
	 * @var Client
24
	 */
25
	protected $client;
26
27
	/**
28
	 * Constructs and initializes an TargetPay gateway
29
	 *
30
	 * @param Config $config Config.
31
	 */
32
	public function __construct( Config $config ) {
33
		parent::__construct( $config );
34
35
		$this->set_method( self::METHOD_HTTP_REDIRECT );
36
37
		// Supported features.
38
		$this->supports = array(
39
			'payment_status_request',
40
		);
41
42
		// Client.
43
		$this->client = new Client();
44
	}
45
46
	/**
47
	 * Get issuers
48
	 *
49
	 * @see Pronamic_WP_Pay_Gateway::get_issuers()
50
	 */
51
	public function get_issuers() {
52
		$groups = array();
53
54
		$result = $this->client->get_issuers();
55
56
		if ( $result ) {
57
			$groups[] = array(
58
				'options' => $result,
59
			);
60
		}
61
62
		return $groups;
63
	}
64
65
	/**
66
	 * Get supported payment methods
67
	 *
68
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
69
	 */
70
	public function get_supported_payment_methods() {
71
		return array(
72
			PaymentMethods::IDEAL,
73
		);
74
	}
75
76
	/**
77
	 * Start
78
	 *
79
	 * @see Core_Gateway::start()
80
	 *
81
	 * @param Payment $payment Payment.
82
	 */
83
	public function start( Payment $payment ) {
84
		$parameters                    = new IDealStartParameters();
85
		$parameters->rtlo              = $this->config->layoutcode;
86
		$parameters->bank              = $payment->get_issuer();
87
		$parameters->description       = $payment->get_description();
88
		$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

88
		$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...
89
		$parameters->return_url        = $payment->get_return_url();
90
		$parameters->report_url        = $payment->get_return_url();
91
		$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...
92
93
		$result = $this->client->start_transaction( $parameters );
94
95
		if ( $result ) {
0 ignored issues
show
introduced by
$result is of type stdClass, thus it always evaluated to true.
Loading history...
96
			$payment->set_action_url( $result->url );
97
			$payment->set_transaction_id( $result->transaction_id );
98
		}
99
	}
100
101
	/**
102
	 * Update status of the specified payment
103
	 *
104
	 * @param Payment $payment Payment.
105
	 */
106
	public function update_status( Payment $payment ) {
107
		// Get transaction status.
108
		$status = $this->client->check_status(
109
			$this->config->layoutcode,
110
			$payment->get_transaction_id(),
111
			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

111
			/** @scrutinizer ignore-type */ false,
Loading history...
112
			self::MODE_TEST === $this->config->mode
113
		);
114
115
		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...
116
			return;
117
		}
118
119
		// Update payment status.
120
		$payment->set_status( Statuses::transform( $status->code ) );
121
122
		// Set payment consumer details.
123
		if ( Statuses::OK === $status->code ) {
124
			$payment->set_consumer_name( $status->account_name );
0 ignored issues
show
Deprecated Code introduced by
The function Pronamic\WordPress\Pay\P...fo::set_consumer_name() has been deprecated: 2.2.6 Use Payment::set_consumer_bank_details()->set_name() instead. ( Ignorable by Annotation )

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

124
			/** @scrutinizer ignore-deprecated */ $payment->set_consumer_name( $status->account_name );

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...
125
			$payment->set_consumer_account_number( $status->account_number );
0 ignored issues
show
Deprecated Code introduced by
The function Pronamic\WordPress\Pay\P...nsumer_account_number() has been deprecated: 2.2.6 Use Payment::set_consumer_bank_details()->set_account_number() instead. ( Ignorable by Annotation )

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

125
			/** @scrutinizer ignore-deprecated */ $payment->set_consumer_account_number( $status->account_number );

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...
126
			$payment->set_consumer_city( $status->account_city );
0 ignored issues
show
Deprecated Code introduced by
The function Pronamic\WordPress\Pay\P...fo::set_consumer_city() has been deprecated: 2.2.6 Use Payment::set_consumer_bank_details()->set_city() instead. ( Ignorable by Annotation )

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

126
			/** @scrutinizer ignore-deprecated */ $payment->set_consumer_city( $status->account_city );

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...
127
		}
128
	}
129
}
130