1 | <?php |
||
25 | class Gateway extends Core_Gateway { |
||
26 | /** |
||
27 | * Client. |
||
28 | * |
||
29 | * @var Client |
||
30 | */ |
||
31 | private $client; |
||
32 | |||
33 | /** |
||
34 | * Constructs and initializes an Payvision gateway. |
||
35 | * |
||
36 | * @param Config $config Config. |
||
37 | */ |
||
38 | 7 | public function __construct( Config $config ) { |
|
51 | |||
52 | /** |
||
53 | * Get issuers |
||
54 | * |
||
55 | * @see Core_Gateway::get_issuers() |
||
56 | * @return array<int, array<string, array<string>>> |
||
|
|||
57 | */ |
||
58 | 1 | public function get_issuers() { |
|
78 | |||
79 | /** |
||
80 | * Get supported payment methods |
||
81 | * |
||
82 | * @see Core_Gateway::get_supported_payment_methods() |
||
83 | * @return array<string> |
||
84 | */ |
||
85 | 1 | public function get_supported_payment_methods() { |
|
90 | |||
91 | /** |
||
92 | * Is payment method required to start transaction? |
||
93 | * |
||
94 | * @see Core_Gateway::payment_method_is_required() |
||
95 | * @return true |
||
96 | */ |
||
97 | 1 | public function payment_method_is_required() { |
|
100 | |||
101 | /** |
||
102 | * Start. |
||
103 | * |
||
104 | * @param Payment $payment Payment. |
||
105 | * @return void |
||
106 | * @throws \InvalidArgumentException Throws exception if payment ID or currency is empty. |
||
107 | */ |
||
108 | 1 | public function start( Payment $payment ) { |
|
109 | 1 | $header = new RequestHeader( $this->config->get_business_id() ); |
|
110 | |||
111 | 1 | $payment_id = $payment->get_id(); |
|
112 | |||
113 | 1 | if ( null === $payment_id ) { |
|
114 | throw new \InvalidArgumentException( 'Can not start payment with empty ID.' ); |
||
115 | } |
||
116 | |||
117 | 1 | $currency_code = $payment->get_total_amount()->get_currency()->get_alphabetic_code(); |
|
118 | |||
119 | 1 | if ( null === $currency_code ) { |
|
120 | throw new \InvalidArgumentException( 'Can not start payment with empty currency code.' ); |
||
121 | } |
||
122 | |||
123 | 1 | $tracking_code = TrackingCode::from_id( $payment_id ); |
|
124 | |||
125 | 1 | $transaction = new Transaction( |
|
126 | 1 | $this->config->get_store_id(), |
|
127 | 1 | $payment->get_total_amount()->get_value(), |
|
128 | $currency_code, |
||
129 | $tracking_code |
||
130 | ); |
||
131 | |||
132 | 1 | $transaction->set_purchase_id( $payment->format_string( (string) $this->config->get_purchase_id() ) ); |
|
133 | 1 | $transaction->set_return_url( $payment->get_return_url() ); |
|
134 | 1 | $transaction->set_brand_id( BrandId::from_core( $payment->get_method() ) ); |
|
135 | 1 | $transaction->set_descriptor( DataHelper::sanitize_an( (string) $payment->get_description(), 127 ) ); |
|
136 | |||
137 | 1 | $payment_request = new PaymentRequest( $header, $transaction ); |
|
138 | |||
139 | // iDEAL. |
||
140 | 1 | if ( BrandId::IDEAL === $transaction->get_brand_id() ) { |
|
141 | $bank = new BankDetails(); |
||
142 | |||
143 | $bank->set_issuer_id( $payment->get_issuer() ); |
||
144 | |||
145 | $payment_request->set_bank( $bank ); |
||
146 | } |
||
147 | |||
148 | 1 | $payment->set_meta( 'payvision_business_id', $this->config->get_business_id() ); |
|
149 | 1 | $payment->set_meta( 'payvision_tracking_code', \strval( $tracking_code ) ); |
|
150 | |||
151 | // Create payment. |
||
152 | 1 | $object = $this->client->send_request( 'POST', '/gateway/v3/payments', \wp_json_encode( $payment_request ) ); |
|
153 | |||
154 | 1 | $payment_response = PaymentResponse::from_json( $object ); |
|
155 | |||
156 | 1 | $error = $payment_response->get_error(); |
|
157 | |||
158 | 1 | if ( null !== $error ) { |
|
159 | throw $error; |
||
160 | } |
||
161 | |||
162 | 1 | if ( null !== $payment_response->redirect ) { |
|
163 | 1 | if ( null !== $payment_response->redirect->url ) { |
|
164 | 1 | $payment->set_action_url( $payment_response->redirect->url ); |
|
165 | } |
||
166 | } |
||
167 | |||
168 | 1 | if ( null !== $payment_response->transaction ) { |
|
169 | 1 | $payment->set_transaction_id( $payment_response->transaction->id ); |
|
170 | } |
||
171 | 1 | } |
|
172 | |||
173 | /** |
||
174 | * Update status of the specified payment. |
||
175 | * |
||
176 | * @param Payment $payment Payment. |
||
177 | * @return void |
||
178 | */ |
||
179 | 5 | public function update_status( Payment $payment ) { |
|
209 | } |
||
210 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.