wp-pay-gateways /
ideal-basic
| 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 | $this->client = new Client(); |
||
| 39 | |||
| 40 | $this->client->set_payment_server_url( $config->get_payment_server_url() ); |
||
| 41 | $this->client->set_merchant_id( $config->merchant_id ); |
||
| 42 | $this->client->set_sub_id( $config->sub_id ); |
||
| 43 | $this->client->set_hash_key( $config->hash_key ); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get output HTML |
||
| 48 | * |
||
| 49 | * @since 1.1.1 |
||
| 50 | * |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | public function get_output_fields() { |
||
| 54 | return $this->client->get_fields(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get supported payment methods |
||
| 59 | * |
||
| 60 | * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() |
||
| 61 | */ |
||
| 62 | public function get_supported_payment_methods() { |
||
| 63 | return array( |
||
| 64 | PaymentMethods::IDEAL, |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Start an transaction with the specified data |
||
| 70 | * |
||
| 71 | * @param Payment $payment Payment. |
||
| 72 | */ |
||
| 73 | public function start( Payment $payment ) { |
||
| 74 | $payment->set_action_url( $this->client->get_payment_server_url() ); |
||
| 75 | |||
| 76 | // Purchase ID. |
||
| 77 | $purchase_id = $payment->format_string( $this->config->purchase_id ); |
||
| 78 | |||
| 79 | $payment->set_meta( 'purchase_id', $purchase_id ); |
||
| 80 | |||
| 81 | // General. |
||
| 82 | $this->client->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ); |
||
| 83 | $this->client->set_purchase_id( $purchase_id ); |
||
| 84 | $this->client->set_description( $payment->get_description() ); |
||
| 85 | |||
| 86 | if ( null !== $payment->get_customer() ) { |
||
| 87 | $this->client->set_language( $payment->get_customer()->get_language() ); |
||
| 88 | } |
||
| 89 | |||
| 90 | // Items. |
||
| 91 | $items = new Items(); |
||
| 92 | |||
| 93 | $items->add_item( new Item( 1, $payment->get_description(), 1, $payment->get_total_amount() ) ); |
||
| 94 | |||
| 95 | $this->client->set_items( $items ); |
||
| 96 | |||
| 97 | // URLs. |
||
| 98 | $this->client->set_cancel_url( add_query_arg( 'status', Statuses::CANCELLED, $payment->get_return_url() ) ); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 99 | $this->client->set_success_url( add_query_arg( 'status', Statuses::SUCCESS, $payment->get_return_url() ) ); |
||
| 100 | $this->client->set_error_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) ); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Update status of the specified payment |
||
| 105 | * |
||
| 106 | * @param Payment $payment Payment. |
||
| 107 | */ |
||
| 108 | public function update_status( Payment $payment ) { |
||
| 109 | if ( ! filter_has_var( INPUT_GET, 'status' ) ) { |
||
| 110 | return; |
||
| 111 | } |
||
| 112 | |||
| 113 | $status = filter_input( INPUT_GET, 'status', FILTER_SANITIZE_STRING ); |
||
| 114 | |||
| 115 | // Update payment status. |
||
| 116 | $payment->set_status( $status ); |
||
| 117 | } |
||
| 118 | } |
||
| 119 |