From 32b3cf2b6b44c099aaa68f18697c5e451b34f542 Mon Sep 17 00:00:00 2001 From: Leith Caldwell Date: Fri, 23 May 2025 14:55:23 +1200 Subject: [PATCH] Add support for the ClientType option to PxPay/PxPost --- src/Message/PxPayAuthorizeRequest.php | 28 ++++++++++++++++++++++++++ src/Message/PxPostAuthorizeRequest.php | 28 ++++++++++++++++++++++++++ tests/PxPayGatewayTest.php | 15 ++++++++++++++ tests/PxPostGatewayTest.php | 18 +++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/src/Message/PxPayAuthorizeRequest.php b/src/Message/PxPayAuthorizeRequest.php index 8b3d67f..802a23f 100644 --- a/src/Message/PxPayAuthorizeRequest.php +++ b/src/Message/PxPayAuthorizeRequest.php @@ -201,6 +201,30 @@ public function setOpt($value) return $this->setParameter('opt', $value); } + /** + * Get the ClientType option + * + * Optional parameter can be used to indicate the type of transaction. Feature may need to be enabled for the user. + * + * @return mixed + */ + public function getClientType() + { + return $this->getParameter('clientType'); + } + + /** + * Set the ClientType field on the request + * + * @param string $value The transaction type, can be one of: 'Internet'/'I' (default), 'Recurring'/'R', or 'MOTO' + * + * @return mixed + */ + public function setClientType($value) + { + return $this->setParameter('clientType', $value); + } + /** * Get the ForcePaymentMethod Opt * @@ -273,6 +297,10 @@ public function getData() $data->Opt = $this->getOpt(); } + if ($this->getClientType()) { + $data->ClientType = $this->getClientType(); + } + if ($this->getForcePaymentMethod()) { $data->ForcePaymentMethod = $this->getForcePaymentMethod(); } diff --git a/src/Message/PxPostAuthorizeRequest.php b/src/Message/PxPostAuthorizeRequest.php index 60594d7..815b378 100644 --- a/src/Message/PxPostAuthorizeRequest.php +++ b/src/Message/PxPostAuthorizeRequest.php @@ -38,6 +38,30 @@ public function getEndpoint() return $this->getTestMode() === true ? $this->testEndpoint : $this->liveEndpoint; } + /** + * Get the ClientType option + * + * Optional parameter can be used to indicate the type of transaction. Feature may need to be enabled for the user. + * + * @return mixed + */ + public function getClientType() + { + return $this->getParameter('clientType'); + } + + /** + * Set the ClientType field on the request + * + * @param string $value The transaction type, can be one of: 'Internet'/'I' (default), 'Recurring'/'R', or 'MOTO' + * + * @return mixed + */ + public function setClientType($value) + { + return $this->setParameter('clientType', $value); + } + /** * @return mixed */ @@ -150,6 +174,10 @@ public function getData() $data->InputCurrency = $this->getCurrency(); $data->Amount = $this->getAmount(); + if ($this->getClientType()) { + $data->ClientType = $this->getClientType(); + } + if ($this->getDescription()) { $data->MerchantReference = $this->getDescription(); } diff --git a/tests/PxPayGatewayTest.php b/tests/PxPayGatewayTest.php index cfc620b..a9037fb 100644 --- a/tests/PxPayGatewayTest.php +++ b/tests/PxPayGatewayTest.php @@ -68,6 +68,21 @@ public function testAuthorizeWithTransactionDataSuccess() $this->_testSuccessfulPurchase($response); } + public function testAuthorizeWithClientTypeSuccess() + { + $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); + + $options = array_merge($this->options, array('clientType' => 'MOTO')); + + $request = $this->gateway->authorize($options); + + $this->assertSame($options['clientType'], $request->getClientType()); + + $response = $request->send(); + + $this->_testSuccessfulPurchase($response); + } + public function testPurchaseSuccess() { $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); diff --git a/tests/PxPostGatewayTest.php b/tests/PxPostGatewayTest.php index 4e61494..420f0a4 100644 --- a/tests/PxPostGatewayTest.php +++ b/tests/PxPostGatewayTest.php @@ -76,6 +76,24 @@ public function testAuthorizeWithTransactionDataSuccess() $this->assertSame('Transaction Approved', $response->getMessage()); } + public function testAuthorizeWithClientTypeSuccess() + { + $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); + + $options = array_merge($this->options, array('clientType' => 'MOTO')); + + $request = $this->gateway->authorize($options); + + $this->assertSame($options['clientType'], $request->getClientType()); + + $response = $request->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('000000030884cdc6', $response->getTransactionReference()); + $this->assertSame('Transaction Approved', $response->getMessage()); + } + public function testCaptureSuccess() { $this->setMockHttpResponse('PxPostPurchaseSuccess.txt');