| @@ 10-95 (lines=86) @@ | ||
| 7 | /** |
|
| 8 | * FACPG2 Tokenize Request |
|
| 9 | */ |
|
| 10 | class CreateCardRequest extends AbstractRequest |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var string; |
|
| 14 | */ |
|
| 15 | protected $requestName = 'TokenizeRequest'; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Returns the signature for the request. |
|
| 19 | * |
|
| 20 | * @return string base64 encoded sha1 hash of the merchantPassword, merchantId, |
|
| 21 | * and acquirerId. |
|
| 22 | */ |
|
| 23 | protected function generateSignature() |
|
| 24 | { |
|
| 25 | $signature = $this->getMerchantPassword(); |
|
| 26 | $signature .= $this->getMerchantId(); |
|
| 27 | $signature .= $this->getAcquirerId(); |
|
| 28 | ||
| 29 | return base64_encode( sha1($signature, true) ); |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Validate and construct the data for the request |
|
| 34 | * |
|
| 35 | * @return array |
|
| 36 | */ |
|
| 37 | public function getData() |
|
| 38 | { |
|
| 39 | $this->validate('merchantId', 'merchantPassword', 'acquirerId', 'customerReference', 'card'); |
|
| 40 | $this->getCard()->validate(); |
|
| 41 | ||
| 42 | $data = [ |
|
| 43 | 'CardNumber' => $this->getCard()->getNumber(), |
|
| 44 | 'CustomerReference' => $this->getCustomerReference(), |
|
| 45 | 'ExpiryDate' => $this->getCard()->getExpiryDate('my'), |
|
| 46 | 'MerchantNumber' => $this->getMerchantId(), |
|
| 47 | 'Signature' => $this->generateSignature() |
|
| 48 | ]; |
|
| 49 | ||
| 50 | return $data; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Get the customer reference. |
|
| 55 | * |
|
| 56 | * @return string |
|
| 57 | */ |
|
| 58 | public function getCustomerReference() |
|
| 59 | { |
|
| 60 | return $this->getParameter('customerReference'); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Set the customer reference. |
|
| 65 | * |
|
| 66 | * @param string $value |
|
| 67 | */ |
|
| 68 | public function setCustomerReference($value) |
|
| 69 | { |
|
| 70 | return $this->setParameter('customerReference', $value); |
|
| 71 | } |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Returns endpoint for tokenize requests |
|
| 75 | * |
|
| 76 | * @return string Endpoint URL |
|
| 77 | */ |
|
| 78 | protected function getEndpoint() |
|
| 79 | { |
|
| 80 | return parent::getEndpoint() . 'Tokenize'; |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Return the tokenize response object |
|
| 85 | * |
|
| 86 | * @param \SimpleXMLElement $xml Response xml object |
|
| 87 | * |
|
| 88 | * @return CreateCardResponse |
|
| 89 | */ |
|
| 90 | protected function newResponse($xml) |
|
| 91 | { |
|
| 92 | return new CreateCardResponse($this, $xml); |
|
| 93 | } |
|
| 94 | ||
| 95 | } |
|
| 96 | ||
| @@ 10-95 (lines=86) @@ | ||
| 7 | /** |
|
| 8 | * FACPG2 Update Token Request |
|
| 9 | */ |
|
| 10 | class UpdateCardRequest extends AbstractRequest |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var string; |
|
| 14 | */ |
|
| 15 | protected $requestName = 'UpdateTokenRequest'; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * Returns the signature for the request. |
|
| 19 | * |
|
| 20 | * @return string base64 encoded sha1 hash of the merchantPassword, merchantId, |
|
| 21 | * and acquirerId. |
|
| 22 | */ |
|
| 23 | protected function generateSignature() |
|
| 24 | { |
|
| 25 | $signature = $this->getMerchantPassword(); |
|
| 26 | $signature .= $this->getMerchantId(); |
|
| 27 | $signature .= $this->getAcquirerId(); |
|
| 28 | ||
| 29 | return base64_encode( sha1($signature, true) ); |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Validate and construct the data for the request |
|
| 34 | * |
|
| 35 | * @return array |
|
| 36 | */ |
|
| 37 | public function getData() |
|
| 38 | { |
|
| 39 | $this->validate('merchantId', 'merchantPassword', 'acquirerId', 'customerReference', 'cardReference', 'card'); |
|
| 40 | $this->getCard()->validate(); |
|
| 41 | ||
| 42 | $data = [ |
|
| 43 | 'CustomerReference' => $this->getCustomerReference(), |
|
| 44 | 'ExpiryDate' => $this->getCard()->getExpiryDate('my'), |
|
| 45 | 'MerchantNumber' => $this->getMerchantId(), |
|
| 46 | 'Signature' => $this->generateSignature(), |
|
| 47 | 'TokenPAN' => $this->getCardReference() |
|
| 48 | ]; |
|
| 49 | ||
| 50 | return $data; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Get the customer reference. |
|
| 55 | * |
|
| 56 | * @return string |
|
| 57 | */ |
|
| 58 | public function getCustomerReference() |
|
| 59 | { |
|
| 60 | return $this->getParameter('customerReference'); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Set the customer reference. |
|
| 65 | * |
|
| 66 | * @param string $value |
|
| 67 | */ |
|
| 68 | public function setCustomerReference($value) |
|
| 69 | { |
|
| 70 | return $this->setParameter('customerReference', $value); |
|
| 71 | } |
|
| 72 | ||
| 73 | /** |
|
| 74 | * Returns endpoint for update token requests |
|
| 75 | * |
|
| 76 | * @return string Endpoint URL |
|
| 77 | */ |
|
| 78 | protected function getEndpoint() |
|
| 79 | { |
|
| 80 | return parent::getEndpoint() . 'UpdateToken'; |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Return the update token response object |
|
| 85 | * |
|
| 86 | * @param \SimpleXMLElement $xml Response xml object |
|
| 87 | * |
|
| 88 | * @return UpdateCardResponse |
|
| 89 | */ |
|
| 90 | protected function newResponse($xml) |
|
| 91 | { |
|
| 92 | return new UpdateCardResponse($this, $xml); |
|
| 93 | } |
|
| 94 | ||
| 95 | } |
|
| 96 | ||