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->supports = array( |
||||
43 | 'payment_status_request', |
||||
44 | ); |
||||
45 | |||||
46 | $this->set_method( self::METHOD_HTTP_REDIRECT ); |
||||
47 | $this->set_slug( self::SLUG ); |
||||
48 | |||||
49 | $this->client = new Client(); |
||||
50 | } |
||||
51 | |||||
52 | /** |
||||
53 | * Get issuers |
||||
54 | * |
||||
55 | * @see Pronamic_WP_Pay_Gateway::get_issuers() |
||||
56 | */ |
||||
57 | public function get_issuers() { |
||||
58 | $groups = array(); |
||||
59 | |||||
60 | $result = $this->client->get_issuers(); |
||||
61 | |||||
62 | if ( $result ) { |
||||
63 | $groups[] = array( |
||||
64 | 'options' => $result, |
||||
65 | ); |
||||
66 | } |
||||
67 | |||||
68 | return $groups; |
||||
69 | } |
||||
70 | |||||
71 | /** |
||||
72 | * Get supported payment methods |
||||
73 | * |
||||
74 | * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() |
||||
75 | */ |
||||
76 | public function get_supported_payment_methods() { |
||||
77 | return array( |
||||
78 | PaymentMethods::IDEAL, |
||||
79 | ); |
||||
80 | } |
||||
81 | |||||
82 | /** |
||||
83 | * Start |
||||
84 | * |
||||
85 | * @see Core_Gateway::start() |
||||
86 | * |
||||
87 | * @param Payment $payment Payment. |
||||
88 | */ |
||||
89 | public function start( Payment $payment ) { |
||||
90 | $parameters = new IDealStartParameters(); |
||||
91 | $parameters->rtlo = $this->config->layoutcode; |
||||
92 | $parameters->bank = $payment->get_issuer(); |
||||
93 | $parameters->description = $payment->get_description(); |
||||
94 | $parameters->amount = $payment->get_total_amount()->get_cents(); |
||||
95 | $parameters->return_url = $payment->get_return_url(); |
||||
96 | $parameters->report_url = $payment->get_return_url(); |
||||
97 | $parameters->cinfo_in_callback = 1; |
||||
0 ignored issues
–
show
|
|||||
98 | |||||
99 | $result = $this->client->start_transaction( $parameters ); |
||||
100 | |||||
101 | if ( $result ) { |
||||
102 | $payment->set_action_url( $result->url ); |
||||
103 | $payment->set_transaction_id( $result->transaction_id ); |
||||
104 | } else { |
||||
105 | $this->set_error( $this->client->get_error() ); |
||||
106 | } |
||||
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 | // Get transaction status. |
||||
116 | $status = $this->client->check_status( |
||||
117 | $this->config->layoutcode, |
||||
118 | $payment->get_transaction_id(), |
||||
119 | 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
![]() |
|||||
120 | self::MODE_TEST === $this->config->mode |
||||
121 | ); |
||||
122 | |||||
123 | if ( ! $status ) { |
||||
124 | return; |
||||
125 | } |
||||
126 | |||||
127 | // Update payment status. |
||||
128 | $payment->set_status( Statuses::transform( $status->code ) ); |
||||
129 | |||||
130 | // Set payment consumer details. |
||||
131 | if ( Statuses::OK === $status->code ) { |
||||
132 | $payment->set_consumer_name( $status->account_name ); |
||||
133 | $payment->set_consumer_account_number( $status->account_number ); |
||||
134 | $payment->set_consumer_city( $status->account_city ); |
||||
135 | } |
||||
136 | } |
||||
137 | } |
||||
138 |
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.