Skip to content
Closed
16 changes: 16 additions & 0 deletions src/Omnipay/SagePay/DirectGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\RefundRequest', $parameters);
}

public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\DirectCreateTokenRequest', $parameters);
}

public function repeatPayment(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\DirectRepeatPaymentRequest', $parameters);
}


public function deleteCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\SagePay\Message\DirectRemoveTokenRequest', $parameters);
}
}
181 changes: 181 additions & 0 deletions src/Omnipay/SagePay/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,187 @@ public function setVendor($value)
return $this->setParameter('vendor', $value);
}

public function getFirstName()
{
return $this->getParameter('firstName');
}

public function setFirstName($value)
{
return $this->setParameter('firstName', $value);
}

public function getLastName()
{
return $this->getParameter('lastName');
}

public function setLastName($value)
{
return $this->setParameter('lastName', $value);
}


public function getBillingAddress1()
{
return $this->getParameter('billingAddress1');
}

public function setBillingAddress1($value)
{
return $this->setParameter('billingAddress1', $value);
}

public function getBillingAddress2()
{
return $this->getParameter('billingAddress2');
}

public function setBillingAddress2($value)
{
return $this->setParameter('billingAddress2', $value);
}

public function getBillingCity()
{
return $this->getParameter('billingCity');
}

public function setBillingCity($value)
{
return $this->setParameter('billingCity', $value);
}

public function getBillingPostcode()
{
return $this->getParameter('billingPostcode');
}

public function setBillingPostcode($value)
{
return $this->setParameter('billingPostcode', $value);
}

public function getBillingState()
{
return $this->getParameter('billingState');
}

public function setBillingState($value)
{
return $this->setParameter('billingState', $value);
}

public function getBillingPhone()
{
return $this->getParameter('billingPhone');
}

public function setBillingPhone($value)
{
return $this->setParameter('billingPhone', $value);
}

public function getBillingCountry()
{
return $this->getParameter('billingCountry');
}

public function setBillingCountry($value)
{
return $this->setParameter('billingCountry', $value);
}

public function getShippingAddress1()
{
return $this->getParameter('shippingAddress1');
}

public function setShippingAddress1($value)
{
return $this->setParameter('shippingAddress1', $value);
}

public function getShippingAddress2()
{
return $this->getParameter('shippingAddress2');
}

public function setShippingAddress2($value)
{
return $this->setParameter('shippingAddress2', $value);
}

public function getShippingCity()
{
return $this->getParameter('shippingCity');
}

public function setShippingCity($value)
{
return $this->setParameter('shippingCity', $value);
}

public function getShippingPostcode()
{
return $this->getParameter('shippingPostcode');
}

public function setShippingPostcode($value)
{
return $this->setParameter('shippingPostcode', $value);
}

public function getShippingState()
{
return $this->getParameter('shippingState');
}

public function setShippingState($value)
{
return $this->setParameter('shippingState', $value);
}

public function getShippingPhone()
{
return $this->getParameter('shippingPhone');
}

public function setShippingPhone($value)
{
return $this->setParameter('shippingPhone', $value);
}

public function getShippingCountry()
{
return $this->getParameter('shippingCountry');
}

public function setShippingCountry($value)
{
return $this->setParameter('shippingCountry', $value);
}

public function getCompany()
{
return $this->getParameter('company');
}

public function setCompany($value)
{
return $this->setParameter('company', $value);
}

public function getEmail()
{
return $this->getParameter('email');
}

public function setEmail($value)
{
return $this->setParameter('email', $value);
}

public function getSimulatorMode()
{
return $this->getParameter('simulatorMode');
Expand Down
138 changes: 100 additions & 38 deletions src/Omnipay/SagePay/Message/DirectAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class DirectAuthorizeRequest extends AbstractRequest

protected function getBaseAuthorizeData()
{
$this->validate('amount', 'card', 'transactionId');
$card = $this->getCard();

$this->validate('amount', 'transactionId');
$data = $this->getBaseData();
$data['Description'] = $this->getDescription();
$data['Amount'] = $this->getAmount();
Expand All @@ -27,50 +25,89 @@ protected function getBaseAuthorizeData()
$data['ApplyAVSCV2'] = 0; // use account setting
$data['Apply3DSecure'] = 0; // use account setting

// billing details
$data['BillingFirstnames'] = $card->getFirstName();
$data['BillingSurname'] = $card->getLastName();
$data['BillingAddress1'] = $card->getBillingAddress1();
$data['BillingAddress2'] = $card->getBillingAddress2();
$data['BillingCity'] = $card->getBillingCity();
$data['BillingPostCode'] = $card->getBillingPostcode();
$data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null;
$data['BillingCountry'] = $card->getBillingCountry();
$data['BillingPhone'] = $card->getBillingPhone();

// shipping details
$data['DeliveryFirstnames'] = $card->getFirstName();
$data['DeliverySurname'] = $card->getLastName();
$data['DeliveryAddress1'] = $card->getShippingAddress1();
$data['DeliveryAddress2'] = $card->getShippingAddress2();
$data['DeliveryCity'] = $card->getShippingCity();
$data['DeliveryPostCode'] = $card->getShippingPostcode();
$data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null;
$data['DeliveryCountry'] = $card->getShippingCountry();
$data['DeliveryPhone'] = $card->getShippingPhone();
$data['CustomerEMail'] = $card->getEmail();

if (!$this->getCardReference()) {
$card = $this->getCard();
// billing details
$data['BillingFirstnames'] = $card->getFirstName();
$data['BillingSurname'] = $card->getLastName();
$data['BillingAddress1'] = $card->getBillingAddress1();
$data['BillingAddress2'] = $card->getBillingAddress2();
$data['BillingCity'] = $card->getBillingCity();
$data['BillingPostCode'] = $card->getBillingPostcode();
$data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : null;
$data['BillingCountry'] = $card->getBillingCountry();
$data['BillingPhone'] = $card->getBillingPhone();

// shipping details
$data['DeliveryFirstnames'] = $card->getFirstName();
$data['DeliverySurname'] = $card->getLastName();
$data['DeliveryAddress1'] = $card->getShippingAddress1();
$data['DeliveryAddress2'] = $card->getShippingAddress2();
$data['DeliveryCity'] = $card->getShippingCity();
$data['DeliveryPostCode'] = $card->getShippingPostcode();
$data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : null;
$data['DeliveryCountry'] = $card->getShippingCountry();
$data['DeliveryPhone'] = $card->getShippingPhone();
$data['CustomerEMail'] = $card->getEmail();
} else {
//Card hasnt been sent so Values need to come from parameteres
$data['BillingFirstnames'] = $this->getFirstName();
$data['BillingSurname'] = $this->getLastName();
$data['BillingAddress1'] = $this->getBillingAddress1();
$data['BillingAddress2'] = $this->getBillingAddress2();
$data['BillingCity'] = $this->getBillingCity();
$data['BillingPostCode'] = $this->getBillingPostcode();
$data['BillingState'] = $this->getBillingCountry() === 'US' ? $this->getBillingState() : null;
$data['BillingCountry'] = $this->getBillingCountry();
$data['BillingPhone'] = $this->getBillingPhone();

// shipping details
$data['DeliveryFirstnames'] = $this->getFirstName();
$data['DeliverySurname'] = $this->getLastName();
$data['DeliveryAddress1'] = $this->getShippingAddress1();
$data['DeliveryAddress2'] = $this->getShippingAddress2();
$data['DeliveryCity'] = $this->getShippingCity();
$data['DeliveryPostCode'] = $this->getShippingPostcode();
$data['DeliveryState'] = $this->getShippingCountry() === 'US' ? $this->getShippingState() : null;
$data['DeliveryCountry'] = $this->getShippingCountry();
$data['DeliveryPhone'] = $this->getShippingPhone();
$data['CustomerEMail'] = $this->getEmail();

}
return $data;
}

public function getData()
{
$data = $this->getBaseAuthorizeData();
$this->getCard()->validate();

//If this is a Token payment, add the Token data item, otherwise its a normal card purchase.
if ($this->getCardReference()) {
$data['Token'] = $this->getCardReference();
$data['CV2'] = $this->getParameter('cvv');
$data['StoreToken'] = 1;

} else {
$this->getCard()->validate();

$data['CardHolder'] = $this->getCard()->getName();
$data['CardNumber'] = $this->getCard()->getNumber();
$data['ExpiryDate'] = $this->getCard()->getExpiryDate('my');
$data['CV2'] = $this->getCard()->getCvv();
$data['CardType'] = $this->getCardBrand();

if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) {
$data['StartDate'] = $this->getCard()->getStartDate('my');
}

if ($this->getCard()->getIssueNumber()) {
$data['IssueNumber'] = $this->getCard()->getIssueNumber();
}

$data['CardHolder'] = $this->getCard()->getName();
$data['CardNumber'] = $this->getCard()->getNumber();
$data['CV2'] = $this->getCard()->getCvv();
$data['ExpiryDate'] = $this->getCard()->getExpiryDate('my');
$data['CardType'] = $this->getCardBrand();

if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) {
$data['StartDate'] = $this->getCard()->getStartDate('my');
}

if ($this->getCard()->getIssueNumber()) {
$data['IssueNumber'] = $this->getCard()->getIssueNumber();
}



return $data;
}
Expand All @@ -90,4 +127,29 @@ protected function getCardBrand()

return $brand;
}


/**
* CVV parameter getter
*
* @return string
*/
public function getCvv()
{
return $this->getParameter('cvv');
}

/**
* CVV parameter setter
* Setter added to allow payments with token and cvv.
* Without setter CVV parameter is stripped out from request parameters.
*
* @param $value string
* @return $this
*/
public function setCvv($value)
{
return $this->setParameter('cvv', $value);
}

}
Loading