|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\AuthorizeNet\Message; |
| 4 | + |
| 5 | +/** |
| 6 | + * Authorize.Net DPM Authorize Request. |
| 7 | + * Takes the data that will be used to create the direct-post form. |
| 8 | + */ |
| 9 | +class DPMAuthorizeRequest extends SIMAuthorizeRequest |
| 10 | +{ |
| 11 | + protected $action = 'AUTH_ONLY'; |
| 12 | + |
| 13 | + public function getData() |
| 14 | + { |
| 15 | + $data = parent::getData(); |
| 16 | + |
| 17 | + // If x_show_form is set, then the form will be displayed on the Authorize.Net |
| 18 | + // gateway, in a similar way to the SIM gateway. The DPM documentation does NOT |
| 19 | + // make this clear at all. |
| 20 | + // Since x_show_form is set in the SIM gateway, make sure we unset it here. |
| 21 | + |
| 22 | + unset($data['x_show_form']); |
| 23 | + |
| 24 | + // Must be set for DPM. |
| 25 | + // This directs all errors to the relay response. |
| 26 | + |
| 27 | + $data['x_relay_always'] = 'TRUE'; |
| 28 | + |
| 29 | + // The card details are optional. |
| 30 | + // They will most likely only be used for development and testing. |
| 31 | + // The card fields are still needed in the direct-post form regardless. |
| 32 | + |
| 33 | + if ($this->getCard()) { |
| 34 | + $data['x_card_num'] = $this->getCard()->getNumber(); |
| 35 | + |
| 36 | + // Workaround for https://github.com/thephpleague/omnipay-common/issues/29 |
| 37 | + $expiry_date = $this->getCard()->getExpiryDate('my'); |
| 38 | + $data['x_exp_date'] = ($expiry_date === '1299' ? '' : $expiry_date); |
| 39 | + |
| 40 | + $data['x_card_code'] = $this->getCard()->getCvv(); |
| 41 | + } else { |
| 42 | + $data['x_card_num'] = ''; |
| 43 | + $data['x_exp_date'] = ''; |
| 44 | + $data['x_card_code'] = ''; |
| 45 | + } |
| 46 | + |
| 47 | + return $data; |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + /** |
| 52 | + * Given the DPM data, we want to turn it into a form for the user to submit to Authorize.net |
| 53 | + * The form may have most of the fields hidden, or may allow the user to change some details - |
| 54 | + * that depends on the use-case. |
| 55 | + * So this method will provide us with an object used to build the form. |
| 56 | + */ |
| 57 | + public function sendData($data) |
| 58 | + { |
| 59 | + return $this->response = new DPMResponse($this, $data, $this->getEndpoint()); |
| 60 | + } |
| 61 | +} |
0 commit comments