Failed Conditions
Push — develop ( abd8c7...e6c5de )
by Remco
04:31
created

src/Gateway.php (2 issues)

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-2019 Pronamic
13
 * Company: Pronamic
14
 *
15
 * @author  Remco Tolsma
16
 * @version 2.0.1
17
 * @since   1.0.0
18
 */
19
class Gateway extends Core_Gateway {
20
	/**
21
	 * Slug of this gateway
22
	 *
23
	 * @var string
24
	 */
25
	const SLUG = 'targetpay';
26
27
	/**
28
	 * Client.
29
	 *
30
	 * @var Client
31
	 */
32
	protected $client;
33
34
	/**
35
	 * Constructs and initializes an TargetPay gateway
36
	 *
37
	 * @param Config $config Config.
38
	 */
39
	public function __construct( Config $config ) {
40
		parent::__construct( $config );
41
42
		$this->set_method( self::METHOD_HTTP_REDIRECT );
43
		$this->set_slug( self::SLUG );
44
45
		// Supported features.
46
		$this->supports = array(
47
			'payment_status_request',
48
		);
49
50
		// Client.
51
		$this->client = new Client();
52
	}
53
54
	/**
55
	 * Get issuers
56
	 *
57
	 * @see Pronamic_WP_Pay_Gateway::get_issuers()
58
	 */
59
	public function get_issuers() {
60
		$groups = array();
61
62
		$result = $this->client->get_issuers();
63
64
		if ( $result ) {
65
			$groups[] = array(
66
				'options' => $result,
67
			);
68
		}
69
70
		return $groups;
71
	}
72
73
	/**
74
	 * Get supported payment methods
75
	 *
76
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
77
	 */
78
	public function get_supported_payment_methods() {
79
		return array(
80
			PaymentMethods::IDEAL,
81
		);
82
	}
83
84
	/**
85
	 * Start
86
	 *
87
	 * @see Core_Gateway::start()
88
	 *
89
	 * @param Payment $payment Payment.
90
	 */
91
	public function start( Payment $payment ) {
92
		$parameters                    = new IDealStartParameters();
93
		$parameters->rtlo              = $this->config->layoutcode;
94
		$parameters->bank              = $payment->get_issuer();
95
		$parameters->description       = $payment->get_description();
96
		$parameters->amount            = $payment->get_total_amount()->get_cents();
97
		$parameters->return_url        = $payment->get_return_url();
98
		$parameters->report_url        = $payment->get_return_url();
99
		$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...
100
101
		$result = $this->client->start_transaction( $parameters );
102
103
		if ( $result ) {
104
			$payment->set_action_url( $result->url );
105
			$payment->set_transaction_id( $result->transaction_id );
106
		} else {
107
			$this->set_error( $this->client->get_error() );
108
		}
109
	}
110
111
	/**
112
	 * Update status of the specified payment
113
	 *
114
	 * @param Payment $payment Payment.
115
	 */
116
	public function update_status( Payment $payment ) {
117
		// Get transaction status.
118
		$status = $this->client->check_status(
119
			$this->config->layoutcode,
120
			$payment->get_transaction_id(),
121
			false,
0 ignored issues
show
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

121
			/** @scrutinizer ignore-type */ false,
Loading history...
122
			self::MODE_TEST === $this->config->mode
123
		);
124
125
		if ( ! $status ) {
126
			return;
127
		}
128
129
		// Update payment status.
130
		$payment->set_status( Statuses::transform( $status->code ) );
131
132
		// Set payment consumer details.
133
		if ( Statuses::OK === $status->code ) {
134
			$payment->set_consumer_name( $status->account_name );
135
			$payment->set_consumer_account_number( $status->account_number );
136
			$payment->set_consumer_city( $status->account_city );
137
		}
138
	}
139
}
140