Failed Conditions
Push — develop ( 7f8e9a...d31cbf )
by Reüel
04:46
created

src/Gateway.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\IDealBasic;
4
5
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
6
use Pronamic\WordPress\Pay\Core\PaymentMethods;
7
use Pronamic\WordPress\Pay\Gateways\IDeal\Statuses;
8
use Pronamic\WordPress\Pay\Payments\Payment;
9
10
/**
11
 * Title: iDEAL Basic gateway
12
 * Description:
13
 * Copyright: 2005-2019 Pronamic
14
 * Company: Pronamic
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.0.1
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
	 * Construct and intialize an 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_HTML_FORM );
37
38
		// Supported features.
39
		$this->supports = array();
40
41
		// Client.
42
		$this->client = new Client();
43
44
		$this->client->set_payment_server_url( $config->get_payment_server_url() );
45
		$this->client->set_merchant_id( $config->merchant_id );
46
		$this->client->set_sub_id( $config->sub_id );
47
		$this->client->set_hash_key( $config->hash_key );
48
	}
49
50
	/**
51
	 * Get supported payment methods
52
	 *
53
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
54
	 */
55
	public function get_supported_payment_methods() {
56
		return array(
57
			PaymentMethods::IDEAL,
58
		);
59
	}
60
61
	/**
62
	 * Start an transaction with the specified data
63
	 *
64
	 * @param Payment $payment Payment.
65
	 */
66
	public function start( Payment $payment ) {
67
		$payment->set_action_url( $this->client->get_payment_server_url() );
68
69
		// Purchase ID.
70
		$purchase_id = $payment->format_string( $this->config->purchase_id );
71
72
		$payment->set_meta( 'purchase_id', $purchase_id );
73
	}
74
75
	/**
76
	 * Get output HTML
77
	 *
78
	 * @param Payment $payment Payment.
79
	 *
80
	 * @return array
81
	 * @since   1.1.1
82
	 * @version 2.0.5
83
	 */
84
	public function get_output_fields( Payment $payment ) {
85
		// General.
86
		$this->client->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() );
87
		$this->client->set_purchase_id( $payment->get_meta( 'purchase_id' ) );
0 ignored issues
show
It seems like $payment->get_meta('purchase_id') can also be of type false; however, parameter $purchase_id of Pronamic\WordPress\Pay\G...ient::set_purchase_id() 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

87
		$this->client->set_purchase_id( /** @scrutinizer ignore-type */ $payment->get_meta( 'purchase_id' ) );
Loading history...
88
		$this->client->set_description( $payment->get_description() );
89
90
		if ( null !== $payment->get_customer() ) {
91
			$this->client->set_language( $payment->get_customer()->get_language() );
92
		}
93
94
		// Items.
95
		$items = new Items();
96
97
		$items->add_item( new Item( 1, $payment->get_description(), 1, $payment->get_total_amount() ) );
98
99
		$this->client->set_items( $items );
100
101
		// URLs.
102
		$this->client->set_cancel_url( add_query_arg( 'status', Statuses::CANCELLED, $payment->get_return_url() ) );
103
		$this->client->set_success_url( add_query_arg( 'status', Statuses::SUCCESS, $payment->get_return_url() ) );
104
		$this->client->set_error_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) );
105
106
		return $this->client->get_fields();
107
	}
108
109
	/**
110
	 * Update status of the specified payment
111
	 *
112
	 * @param Payment $payment Payment.
113
	 */
114
	public function update_status( Payment $payment ) {
115
		if ( ! filter_has_var( INPUT_GET, 'status' ) ) {
116
			return;
117
		}
118
119
		$status = filter_input( INPUT_GET, 'status', FILTER_SANITIZE_STRING );
120
121
		// Update payment status.
122
		$payment->set_status( $status );
123
	}
124
}
125