From 1e58c10b58d7e444b7cfb3605244d05d7004f54c Mon Sep 17 00:00:00 2001 From: Patrick Zirnig Date: Tue, 20 Feb 2024 10:11:11 +0100 Subject: [PATCH] Extend CreateCustomer --- examples/createcustomer.php | 12 +++++++-- src/Responses/CreateCustomerResponse.php | 33 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/examples/createcustomer.php b/examples/createcustomer.php index ef68872..464a0ad 100644 --- a/examples/createcustomer.php +++ b/examples/createcustomer.php @@ -21,10 +21,14 @@ if (isset($_POST["token"])) { $payment = array( - "token" => $_POST["token"] + "token" => $_POST["token"], + "validate" => "true" ); $additional = array( + "successURL" => "http://yourdomain.com/success", + "errorURL" => "http://yourdomain.com/error", + "confirmationURL" => "http://yourdomain.com/confirmation", "billingAddress" => array( "mode" => "READONLY", "name" => "John Doe", @@ -36,7 +40,11 @@ ); $result = $mpay24->createCustomer("TOKEN", "123456", $payment, $additional); - echo $result->getReturnCode(); + if ($result->getReturnCode() == "REDIRECT") { + header("Location: " . $result->getLocation()); + } else { + echo $result->getReturnCode(); + } } ?> diff --git a/src/Responses/CreateCustomerResponse.php b/src/Responses/CreateCustomerResponse.php index eb276c0..10a2284 100644 --- a/src/Responses/CreateCustomerResponse.php +++ b/src/Responses/CreateCustomerResponse.php @@ -19,6 +19,16 @@ class CreateCustomerResponse extends AbstractResponse * @var int */ protected $errNo; + + /** + * @var string + */ + protected $errText; + + /** + * @var string + */ + protected $location; /** * CreateCustomerResponse constructor. @@ -44,6 +54,22 @@ public function getErrNo() { return $this->errNo; } + + /** + * @return string + */ + public function getErrText() + { + return $this->errText; + } + + /** + * @return string + */ + public function getLocation() + { + return $this->location; + } /** * Parse the CreateCustomerResponse message and save the data to the corresponding attributes @@ -52,8 +78,15 @@ public function getErrNo() */ protected function parseResponse($body) { + $this->location = $body->getElementsByTagName('location')->item(0)->nodeValue; + + if ($body->getElementsByTagName('errNo')->length > 0) { $this->errNo = (int)$body->getElementsByTagName('errNo')->item(0)->nodeValue; } + + if ($body->getElementsByTagName('errText')->length > 0) { + $this->errText = $body->getElementsByTagName('errText')->item(0)->nodeValue; + } } }