Skip to content

Commit

Permalink
null values are now removed from payload
Browse files Browse the repository at this point in the history
  • Loading branch information
w3guy committed Jan 17, 2017
1 parent ac2e378 commit 1f2f02b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
*/
class PurchaseRequest extends AbstractRequest
{
public function isNotNull($value)
{
return !is_null($value);
}

public function getData()
{
$this->validate('transactionId', 'amount', 'currency', 'type', 'description', 'accountId');

$data = array();
$data['account_id'] = $this->getAccountId();
// its important that unique and reference ID are strings else it becomes invalid
$data['reference_id'] = (string) $this->getTransactionId();
$data['reference_id'] = (string)$this->getTransactionId();
$data['amount'] = $this->getAmount();
$data['type'] = $this->getType();
$data['currency'] = $this->getCurrency();
Expand All @@ -33,7 +38,7 @@ public function getData()
// this is highly encouraged to prevent duplicate transactions on a single order.
// see footnote in https://www.wepay.com/developer/reference/checkout#create
// its important that unique and reference ID are strings else it becomes invalid
$data['unique_id'] = (string) $this->getTransactionId();
$data['unique_id'] = (string)$this->getTransactionId();

if ($this->getPaymentMethodType() == 'payment_bank') {
$data['payment_method']['type'] = 'payment_bank';
Expand Down Expand Up @@ -71,13 +76,17 @@ public function getData()
'name' => $this->getCard()->getName(),
'email' => $this->getCard()->getEmail(),
'phone_number' => $this->getCard()->getPhone(),
'address' => array(
'address1' => $this->getCard()->getAddress1(),
'address2' => $this->getCard()->getAddress2(),
'city' => $this->getCard()->getCity(),
'region' => $this->getCard()->getState(),
'country' => $this->getCard()->getCountry(),
'postal_code' => $this->getCard()->getPostcode()
// filter out null values
'address' => array_filter(
array(
'address1' => $this->getCard()->getAddress1(),
'address2' => $this->getCard()->getAddress2(),
'city' => $this->getCard()->getCity(),
'region' => $this->getCard()->getState(),
'country' => $this->getCard()->getCountry(),
'postal_code' => $this->getCard()->getPostcode()
),
array($this, 'isNotNull')
)
);

Expand Down

0 comments on commit 1f2f02b

Please sign in to comment.