1 | <?php |
||
2 | |||
3 | namespace Pronamic\WordPress\Pay\Gateways\TargetPay; |
||
4 | |||
5 | use Pronamic\WordPress\Pay\Banks\BankAccountDetails; |
||
6 | use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
||
7 | use Pronamic\WordPress\Pay\Core\PaymentMethods; |
||
8 | use Pronamic\WordPress\Pay\Payments\Payment; |
||
9 | |||
10 | /** |
||
11 | * Title: TargetPay gateway |
||
12 | * Description: |
||
13 | * Copyright: 2005-2021 Pronamic |
||
14 | * Company: Pronamic |
||
15 | * |
||
16 | * @author Remco Tolsma |
||
17 | * @version 2.0.3 |
||
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 | * Constructs and initializes an TargetPay 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_HTTP_REDIRECT ); |
||
37 | |||
38 | // Supported features. |
||
39 | $this->supports = array( |
||
40 | 'payment_status_request', |
||
41 | ); |
||
42 | |||
43 | // Client. |
||
44 | $this->client = new Client(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Get issuers |
||
49 | * |
||
50 | * @see Pronamic_WP_Pay_Gateway::get_issuers() |
||
51 | */ |
||
52 | public function get_issuers() { |
||
53 | $groups = array(); |
||
54 | |||
55 | $result = $this->client->get_issuers(); |
||
56 | |||
57 | if ( $result ) { |
||
58 | $groups[] = array( |
||
59 | 'options' => $result, |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | return $groups; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get supported payment methods |
||
68 | * |
||
69 | * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() |
||
70 | */ |
||
71 | public function get_supported_payment_methods() { |
||
72 | return array( |
||
73 | PaymentMethods::IDEAL, |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Start |
||
79 | * |
||
80 | * @see Core_Gateway::start() |
||
81 | * |
||
82 | * @param Payment $payment Payment. |
||
83 | */ |
||
84 | public function start( Payment $payment ) { |
||
85 | $parameters = new IDealStartParameters(); |
||
86 | $parameters->rtlo = $this->config->layoutcode; |
||
87 | $parameters->bank = $payment->get_issuer(); |
||
88 | $parameters->description = $payment->get_description(); |
||
89 | $parameters->amount = $payment->get_total_amount()->get_cents(); |
||
90 | $parameters->return_url = $payment->get_return_url(); |
||
91 | $parameters->report_url = $payment->get_return_url(); |
||
92 | $parameters->cinfo_in_callback = 1; |
||
0 ignored issues
–
show
|
|||
93 | |||
94 | $result = $this->client->start_transaction( $parameters ); |
||
95 | |||
96 | if ( $result ) { |
||
97 | $payment->set_action_url( $result->url ); |
||
98 | $payment->set_transaction_id( $result->transaction_id ); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Update status of the specified payment |
||
104 | * |
||
105 | * @param Payment $payment Payment. |
||
106 | */ |
||
107 | public function update_status( Payment $payment ) { |
||
108 | // Get transaction status. |
||
109 | $status = $this->client->check_status( |
||
110 | $this->config->layoutcode, |
||
111 | $payment->get_transaction_id(), |
||
112 | false, |
||
113 | self::MODE_TEST === $this->config->mode |
||
114 | ); |
||
115 | |||
116 | if ( ! $status ) { |
||
117 | return; |
||
118 | } |
||
119 | |||
120 | // Update payment status. |
||
121 | $payment->set_status( Statuses::transform( $status->code ) ); |
||
122 | |||
123 | // Set payment consumer details. |
||
124 | if ( Statuses::OK === $status->code ) { |
||
125 | $consumer_bank_details = $payment->get_consumer_bank_details(); |
||
126 | |||
127 | if ( null === $consumer_bank_details ) { |
||
128 | $consumer_bank_details = new BankAccountDetails(); |
||
129 | |||
130 | $payment->set_consumer_bank_details( $consumer_bank_details ); |
||
131 | } |
||
132 | |||
133 | $consumer_bank_details->set_name( $status->account_name ); |
||
134 | $consumer_bank_details->set_account_number( $status->account_number ); |
||
135 | $consumer_bank_details->set_city( $status->account_city ); |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 |
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.