Skip to content

Commit 8f916c2

Browse files
committed
Updated request data to correctly set MerchantRef
1 parent eb78592 commit 8f916c2

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/Message/PurchaseRequest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,38 @@ public function getData()
5252
$data['CurrencyCode'] = $this->getCurrency();
5353
$data['MerchantCheckoutURL'] = $this->getCancelUrl();
5454
$data['MerchantCode'] = $this->getMerchantCode();
55+
$data['MerchantData'] = $this->getTransactionId();
5556
$data['MerchantDateTime'] = date('Y-m-d\TH:i:s');
5657
$data['MerchantHomePageURL'] = $this->getCancelUrl();
57-
$data['MerchantRef'] = $this->getTransactionId();
58+
$data['MerchantRef'] = $this->getCombinedMerchantRef();
59+
$data['MerchantReferenceFormat'] = 1;
5860
$data['NotificationURL'] = $this->getNotifyUrl();
5961
$data['SuccessfulURL'] = $this->getReturnUrl();
6062
$data['Timeout'] = 0;
6163
$data['UnsuccessfulURL'] = $this->getReturnUrl();
62-
$data['MerchantData'] = $this->getTransactionReference();
63-
$data['MerchantReferenceFormat'] = 0;
6464
$data['UserIPAddress'] = $this->getClientIp();
6565

6666
return $data;
6767
}
6868

69+
/**
70+
* Generate reference data
71+
* @link http://www.polipaymentdeveloper.com/doku.php?id=nzreconciliation
72+
*/
73+
protected function getCombinedMerchantRef(){
74+
$card = $this->getCard();
75+
$id = $this->cleanField($this->getTransactionId());
76+
$data = array($this->cleanField($card->getName()), "", $id);
77+
return implode("|", $data);
78+
}
79+
80+
/**
81+
* Data in reference field must not contain illegal characters
82+
*/
83+
protected function cleanField($field){
84+
return substr($field,0,12);
85+
}
86+
6987
public function send()
7088
{
7189
$postdata = $this->packageData($this->getData());
@@ -75,7 +93,7 @@ public function send()
7593
$postdata
7694
);
7795
$httpResponse = $httpRequest->send();
78-
96+
echo $httpResponse->getBody();
7997
return $this->response = new PurchaseResponse($this, $httpResponse->getBody());
8098
}
8199

0 commit comments

Comments
 (0)