Skip to content

Commit

Permalink
Merge pull request #38 from rondogency/sales-tax-address
Browse files Browse the repository at this point in the history
Add sales tax address info to credit card shipping address field
  • Loading branch information
Ziyi Mu authored Jul 24, 2018
2 parents 260f98b + 0ca171f commit 9aaf733
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 89 deletions.
77 changes: 54 additions & 23 deletions src/ObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ class ObjectHelper
public function buildTransaction(stdClass $object)
{
$customer = isset($object->account) ? $this->buildCustomer($object->account) : null;
$paymentMethod = isset($object->sourcePaymentMethod)
? $this->buildPaymentMethod($object->sourcePaymentMethod)
: null;

// fetch transaction response may have salesTaxAddress field as shipping address
// we should dump this info into the card and use it when creating transaction record
$paymentMethod = null;
if (isset($object->sourcePaymentMethod)) {
$sales_tax_address = isset($object->salesTaxAddress) ? $object->salesTaxAddress : null;
$paymentMethod = $this->buildPaymentMethod($object->sourcePaymentMethod, $sales_tax_address);
}

$items = null;
if (isset($object->transactionItems)) {
Expand Down Expand Up @@ -144,9 +149,11 @@ public function buildCustomer(stdClass $object)
}

/**
* @param stdClass $object raw payment object
* @param stdClass $salesTaxAddress salesTaxAddress info from fetch transaction response
* @return \Omnipay\Vindicia\PaymentMethod
*/
public function buildPaymentMethod(stdClass $object)
public function buildPaymentMethod(stdClass $object, stdClass $salesTaxAddress = null)
{
$cvv = null;
$nameValues = null;
Expand All @@ -163,30 +170,54 @@ public function buildPaymentMethod(stdClass $object)
}
}

return new PaymentMethod(array(
'paymentMethodId' => isset($object->merchantPaymentMethodId) ? $object->merchantPaymentMethodId : null,
'paymentMethodReference' => isset($object->VID) ? $object->VID : null,
'type' => isset($object->type) ? $object->type : null,
'postcode' => isset($object->billingAddress->postalCode) ? $object->billingAddress->postalCode : null,
'country' => isset($object->billingAddress->country) ? $object->billingAddress->country : null,
// NonStrippingCreditCard won't remove the X's that Vindicia masks with
'card' => new NonStrippingCreditCard(array(
'name' => isset($object->accountHolderName) ? $object->accountHolderName : null,
$card_info = array(
'name' => isset($object->accountHolderName) ? $object->accountHolderName : null,
'number' => isset($object->creditCard->account) ? $object->creditCard->account : null,
'expiryMonth' => isset($object->creditCard->expirationDate)
? substr($object->creditCard->expirationDate, 4)
: null,
'expiryYear' => isset($object->creditCard->expirationDate)
? substr($object->creditCard->expirationDate, 0, 4)
: null,
'cvv' => $cvv
);

$address_info = null;
if ($salesTaxAddress === null) {
$address_info = array(
'address1' => isset($object->billingAddress->addr1) ? $object->billingAddress->addr1 : null,
'address2' => isset($object->billingAddress->addr2) ? $object->billingAddress->addr2 : null,
'city' => isset($object->billingAddress->city) ? $object->billingAddress->city : null,
'postcode' => isset($object->billingAddress->postalCode) ? $object->billingAddress->postalCode : null,
'state' => isset($object->billingAddress->district) ? $object->billingAddress->district : null,
'country' => isset($object->billingAddress->country) ? $object->billingAddress->country : null,
'number' => isset($object->creditCard->account) ? $object->creditCard->account : null,
'expiryMonth' => isset($object->creditCard->expirationDate)
? substr($object->creditCard->expirationDate, 4)
: null,
'expiryYear' => isset($object->creditCard->expirationDate)
? substr($object->creditCard->expirationDate, 0, 4)
: null,
'cvv' => $cvv
)),
'country' => isset($object->billingAddress->country) ? $object->billingAddress->country : null
);
} else {
$address_info = array(
'billingAddress1' => isset($object->billingAddress->addr1) ? $object->billingAddress->addr1 : null,
'billingAddress2' => isset($object->billingAddress->addr2) ? $object->billingAddress->addr2 : null,
'billingCity' => isset($object->billingAddress->city) ? $object->billingAddress->city : null,
'billingPostcode' => isset($object->billingAddress->postalCode)
? $object->billingAddress->postalCode
: null,
'billingState' => isset($object->billingAddress->district) ? $object->billingAddress->district : null,
'billingCountry' => isset($object->billingAddress->country) ? $object->billingAddress->country : null,
'shippingAddress1' => isset($salesTaxAddress->addr1) ? $salesTaxAddress->addr1 : null,
'shippingAddress2' => isset($salesTaxAddress->addr2) ? $salesTaxAddress->addr2 : null,
'shippingCity' => isset($salesTaxAddress->city) ? $salesTaxAddress->city : null,
'shippingPostcode' => isset($salesTaxAddress->postalCode) ? $salesTaxAddress->postalCode : null,
'shippingState' => isset($salesTaxAddress->district) ? $salesTaxAddress->district : null,
'shippingCountry' => isset($salesTaxAddress->country) ? $salesTaxAddress->country : null
);
}
$card_info = array_merge($card_info, $address_info);

return new PaymentMethod(array(
'paymentMethodId' => isset($object->merchantPaymentMethodId) ? $object->merchantPaymentMethodId : null,
'paymentMethodReference' => isset($object->VID) ? $object->VID : null,
'type' => isset($object->type) ? $object->type : null,
// NonStrippingCreditCard won't remove the X's that Vindicia masks with
'card' => new NonStrippingCreditCard($card_info),
'attributes' => isset($nameValues) ? $this->buildAttributes($nameValues) : null
));
}
Expand Down
42 changes: 0 additions & 42 deletions src/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,48 +198,6 @@ public function setType($value)
return $this->setParameter('type', $value);
}

/**
* Get the billing postcode.
*
* @return null|string
*/
public function getPostcode()
{
return $this->getParameter('postcode');
}

/**
* Sets the billing postcode.
*
* @param string $value
* @return static
*/
public function setPostcode($value)
{
return $this->setParameter('postcode', $value);
}

/**
* Get the billing country.
*
* @return null|string
*/
public function getCountry()
{
return $this->getParameter('country');
}

/**
* Sets the billing country.
*
* @param string $value
* @return static
*/
public function setCountry($value)
{
return $this->setParameter('country', $value);
}

/**
* A list of attributes
*
Expand Down
7 changes: 4 additions & 3 deletions tests/Message/FetchPaymentMethodRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ public function testSendPayPalSuccess()
'PAYMENT_METHOD_REFERENCE' => $this->paymentMethodReference,
'COUNTRY' => $this->card['country'],
'POSTCODE' => $this->card['postcode']

));

$response = $this->request->send();
Expand All @@ -222,8 +221,10 @@ public function testSendPayPalSuccess()
$this->assertSame($this->paymentMethodId, $paymentMethod->getId());
$this->assertSame($this->paymentMethodReference, $paymentMethod->getReference());
$this->assertSame('PayPal', $paymentMethod->getType());
$this->assertSame($this->card['country'], $paymentMethod->getCountry());
$this->assertSame($this->card['postcode'], $paymentMethod->getPostcode());
$card = $paymentMethod->getCard();
$this->assertInstanceOf('\Omnipay\Common\CreditCard', $card);
$this->assertSame($this->card['country'], $card->getCountry());
$this->assertSame($this->card['postcode'], $card->getPostcode());

$attributes = $paymentMethod->getAttributes();
$this->assertSame(2, count($attributes));
Expand Down
23 changes: 22 additions & 1 deletion tests/Message/FetchTransactionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public function setUp()

/* timestamp should set to current time or it will break vod test */
$this->timestamp = date('Y-m-d\T12:00:00-04:00');

$this->billingPostcode = $this->faker->postcode();
$this->billingCountry = $this->faker->region();
$this->shippingPostcode = $this->faker->postcode();
$this->shippingCountry = $this->faker->region();
$this->shippingAddress1 = $this->faker->randomCharacters(DataFaker::ALPHABET_UPPER, 12);
$this->shippingCity = $this->faker->randomCharacters(DataFaker::ALPHABET_UPPER, 8);
}

/**
Expand Down Expand Up @@ -131,7 +138,13 @@ public function testSendSuccess()
'AUTHORIZATION_CODE' => $this->authorizationCode,
'CVV_CODE' => $this->cvvCode,
'AVS_CODE' => $this->avsCode,
'TIMESTAMP' => $this->timestamp
'TIMESTAMP' => $this->timestamp,
'POSTCODE' => $this->billingPostcode,
'COUNTRY' => $this->billingCountry,
'SHIPPING_POSTCODE' => $this->shippingPostcode,
'SHIPPING_COUNTRY' => $this->shippingCountry,
'SHIPPING_ADDRESS_1' => $this->shippingAddress1,
'SHIPPING_CITY'=> $this->shippingCity
));

$response = $this->request->send();
Expand Down Expand Up @@ -195,6 +208,14 @@ public function testSendSuccess()
}
$this->assertEquals($this->timestamp, $transaction->getTimestamp());

$card = $paymentMethod->getCard();
$this->assertEquals($this->billingPostcode, $card->getPostcode());
$this->assertEquals($this->billingCountry, $card->getCountry());
$this->assertEquals($this->shippingPostcode, $card->getShippingPostcode());
$this->assertEquals($this->shippingCountry, $card->getShippingCountry());
$this->assertEquals($this->shippingAddress1, $card->getShippingAddress1());
$this->assertEquals($this->shippingCity, $card->getShippingCity());

$this->assertSame('https://soap.prodtest.sj.vindicia.com/18.0/Transaction.wsdl', $this->getLastEndpoint());
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Mock/FetchTransactionSuccess.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
<subtotal xmlns="" xsi:type="xsd:decimal">0</subtotal>
<total xmlns="" xsi:type="xsd:decimal">[TAX_AMOUNT]</total>
</transactionItems>
<salesTaxAddress>
<VID xmlns="" xsi:type="xsd:string">5b484390ebb889cd2f4fe9523c7720b8653406ed</VID>
<addr1 xmlns="" xsi:type="xsd:string">[SHIPPING_ADDRESS_1]</addr1>
<city xmlns="" xsi:type="xsd:string">[SHIPPING_CITY]</city>
<postalCode xmlns="" xsi:type="xsd:string">[SHIPPING_POSTCODE]</postalCode>
<country xmlns="" xsi:type="xsd:string">[SHIPPING_COUNTRY]</country>
</salesTaxAddress>
<sourceIp xmlns="" xsi:type="xsd:string">[IP_ADDRESS]</sourceIp>
<nameValues xmlns="" xsi:type="vin:NameValuePair">
<name xmlns="" xsi:type="xsd:string">[ATTRIBUTE_1_NAME]</name>
Expand Down
20 changes: 0 additions & 20 deletions tests/PaymentMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,6 @@ public function testType()
$this->assertSame($type, $this->paymentMethod->getType());
}

/**
* @return void
*/
public function testPostcode()
{
$postcode = $this->faker->postcode();
$this->assertSame($this->paymentMethod, $this->paymentMethod->setPostcode($postcode));
$this->assertSame($postcode, $this->paymentMethod->getPostcode());
}

/**
* @return void
*/
public function testCountry()
{
$country = $this->faker->region();
$this->assertSame($this->paymentMethod, $this->paymentMethod->setCountry($country));
$this->assertSame($country, $this->paymentMethod->getCountry());
}

/**
* @return void
*/
Expand Down

0 comments on commit 9aaf733

Please sign in to comment.