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