Skip to content

Commit

Permalink
Merge pull request #36 from rondogency/payment-type
Browse files Browse the repository at this point in the history
Add new fields in Payment Method object
  • Loading branch information
Ziyi Mu authored Jun 29, 2018
2 parents e651272 + 94c18da commit b0f375c
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function setEmail($value)
/**
* Get the customer's tax exemptions
*
* @return null|TaxExemptionBag
* @return null|array
*/
public function getTaxExemptions()
{
Expand Down
3 changes: 3 additions & 0 deletions src/ObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ 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,
Expand Down
63 changes: 63 additions & 0 deletions src/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,69 @@ public function setCard($value)
return $this->setParameter('card', $value);
}

/**
* Get the payment method type, either PayPal or CreditCard
*
* @return null|string
*/
public function getType()
{
return $this->getParameter('type');
}

/**
* Sets the payment method type
*
* @param string $value
* @return static
*/
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
39 changes: 39 additions & 0 deletions tests/Message/FetchPaymentMethodRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,43 @@ public function testSendByReferenceFailure()

$this->assertNull($response->getPaymentMethod());
}

/**
* @return void
*/
public function testSendPayPalSuccess()
{
$this->setMockSoapResponse('FetchPayPalPaymentMethodSuccess.xml', array(
'PAYMENT_METHOD_ID' => $this->paymentMethodId,
'PAYMENT_METHOD_REFERENCE' => $this->paymentMethodReference,
'COUNTRY' => $this->card['country'],
'POSTCODE' => $this->card['postcode']

));

$response = $this->request->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertFalse($response->isPending());
$this->assertSame('OK', $response->getMessage());

$paymentMethod = $response->getPaymentMethod();
$this->assertInstanceOf('\Omnipay\Vindicia\PaymentMethod', $paymentMethod);
$this->assertSame($this->paymentMethodId, $response->getPaymentMethodId());
$this->assertSame($this->paymentMethodReference, $response->getPaymentMethodReference());
$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());

$attributes = $paymentMethod->getAttributes();
$this->assertSame(2, count($attributes));
foreach ($attributes as $attribute) {
$this->assertInstanceOf('\Omnipay\Vindicia\Attribute', $attribute);
}

$this->assertSame('https://soap.prodtest.sj.vindicia.com/18.0/PaymentMethod.wsdl', $this->getLastEndpoint());
}
}
38 changes: 38 additions & 0 deletions tests/Mock/FetchPayPalPaymentMethodSuccess.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:vin="http://soap.vindicia.com/v18_0/Vindicia"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<fetchByMerchantPaymentMethodIdResponse xmlns="http://soap.vindicia.com/v18_0/PaymentMethod">
<return xmlns="" xsi:type="vin:Return">
<returnCode xsi:type="vin:ReturnCode">200</returnCode>
<soapId xsi:type="xsd:string">1234567890abcdef1234567890abcdef</soapId>
<returnString xsi:type="xsd:string">OK</returnString>
</return>
<paymentMethod xmlns="" xsi:type="vin:PaymentMethod">
<VID xmlns="" xsi:type="xsd:string">[PAYMENT_METHOD_REFERENCE]</VID>
<type xmlns="" xsi:type="vin:PaymentMethodType">PayPal</type>
<nameValues xmlns="" xsi:type="vin:NameValuePair">
<name xmlns="" xsi:type="xsd:string">attributeName</name>
<value xmlns="" xsi:type="xsd:string">attributeValue</value>
</nameValues>
<nameValues xmlns="" xsi:type="vin:NameValuePair">
<name xmlns="" xsi:type="xsd:string">attributeName</name>
<value xmlns="" xsi:type="xsd:string">attributeValue</value>
</nameValues>
<billingAddress xmlns="" xsi:type="vin:Address">
<VID xmlns="" xsi:type="xsd:string">99988877766655544433322211100000</VID>
<postalCode xmlns="" xsi:type="xsd:string">[POSTCODE]</postalCode>
<country xmlns="" xsi:type="xsd:string">[COUNTRY]</country>
</billingAddress>
<merchantPaymentMethodId xmlns="" xsi:type="xsd:string">[PAYMENT_METHOD_ID]</merchantPaymentMethodId>
<sortOrder xmlns="" xsi:type="xsd:int">0</sortOrder>
<active xmlns="" xsi:type="xsd:boolean">1</active>
</paymentMethod>
</fetchByMerchantPaymentMethodIdResponse>
</soap:Body>
</soap:Envelope>
30 changes: 30 additions & 0 deletions tests/PaymentMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,36 @@ public function testCard()
$this->assertSame($card, $this->paymentMethod->getCard());
}

/**
* @return void
*/
public function testType()
{
$type = 'PayPal';
$this->assertSame($this->paymentMethod, $this->paymentMethod->setType($type));
$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 b0f375c

Please sign in to comment.