Failed Conditions
Push — feature/webhook-status ( c2cf79 )
by Reüel
05:45
created

Gateway::get_supported_features()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 = self::get_supported_features();
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 features.
52
	 *
53
	 * @return array
54
	 */
55
	public static function get_supported_features() {
56
		return array(
57
			'webhook_manual_config',
58
		);
59
	}
60
61
	/**
62
	 * Get output HTML
63
	 *
64
	 * @since 1.1.1
65
	 *
66
	 * @return array
67
	 */
68
	public function get_output_fields() {
69
		return $this->client->get_fields();
70
	}
71
72
	/**
73
	 * Get supported payment methods
74
	 *
75
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
76
	 */
77
	public function get_supported_payment_methods() {
78
		return array(
79
			PaymentMethods::IDEAL,
80
		);
81
	}
82
83
	/**
84
	 * Start an transaction with the specified data
85
	 *
86
	 * @param Payment $payment Payment.
87
	 */
88
	public function start( Payment $payment ) {
89
		$payment->set_action_url( $this->client->get_payment_server_url() );
90
91
		// Purchase ID.
92
		$purchase_id = $payment->format_string( $this->config->purchase_id );
93
94
		$payment->set_meta( 'purchase_id', $purchase_id );
95
96
		// General.
97
		$this->client->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() );
98
		$this->client->set_purchase_id( $purchase_id );
99
		$this->client->set_description( $payment->get_description() );
100
101
		if ( null !== $payment->get_customer() ) {
102
			$this->client->set_language( $payment->get_customer()->get_language() );
103
		}
104
105
		// Items.
106
		$items = new Items();
107
108
		$items->add_item( new Item( 1, $payment->get_description(), 1, $payment->get_total_amount() ) );
109
110
		$this->client->set_items( $items );
111
112
		// URLs.
113
		$this->client->set_cancel_url( add_query_arg( 'status', Statuses::CANCELLED, $payment->get_return_url() ) );
114
		$this->client->set_success_url( add_query_arg( 'status', Statuses::SUCCESS, $payment->get_return_url() ) );
115
		$this->client->set_error_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) );
116
	}
117
118
	/**
119
	 * Update status of the specified payment
120
	 *
121
	 * @param Payment $payment Payment.
122
	 */
123
	public function update_status( Payment $payment ) {
124
		if ( ! filter_has_var( INPUT_GET, 'status' ) ) {
125
			return;
126
		}
127
128
		$status = filter_input( INPUT_GET, 'status', FILTER_SANITIZE_STRING );
129
130
		// Update payment status.
131
		$payment->set_status( $status );
132
	}
133
}
134