Skip to content

Commit

Permalink
Tiny bit of refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Oram committed Nov 14, 2013
1 parent 320db20 commit 3d1ce10
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/SclZfCartSagepay/Sagepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace SclZfCartSagepay;

use SclZfCart\Entity\OrderInterface;
use SclZfCartPayment\Entity\PaymentInterface;
use SclZfCartPayment\PaymentMethodInterface;
use SclZfCartSagepay\Data\CryptData;
use SclZfCartSagepay\Encryption\Cipher;
use SclZfCartSagepay\Options\SagepayOptions;
use SclZfCart\Customer\CustomerInterface;
use SclZfCart\Entity\OrderInterface;
use SclZfSequenceGenerator\SequenceGeneratorInterface;
use SclZfUtilities\Route\UrlBuilder;
use Zend\Form\Form;
Expand Down Expand Up @@ -64,25 +65,35 @@ class Sagepay implements PaymentMethodInterface
*/
private $sequenceGenerator;

/**
* The customer object
*
* @var Customer
*/
private $customer;

/**
* @param SagepayOptions $provider
* @param Cipher $cipher
* @param CryptData $cryptData
* @param UrlBuilder $urlBuilder
* @param SequenceGeneratorInterface $sequenceGenerator
* @param CustomerInterface $customer
*/
public function __construct(
SagepayOptions $options,
Cipher $cipher,
CryptData $cryptData,
UrlBuilder $urlBuilder,
SequenceGeneratorInterface $sequenceGenerator
SequenceGeneratorInterface $sequenceGenerator,
CustomerInterface $customer
) {
$this->options = $options;
$this->cipher = $cipher;
$this->cryptData = $cryptData;
$this->urlBuilder = $urlBuilder;
$this->sequenceGenerator = $sequenceGenerator;
$this->customer = $customer;
}

/**
Expand Down Expand Up @@ -114,6 +125,20 @@ private function addHiddenField(Form $form, $name, $value)
);
}

private function addContact(CryptData $cryptData, $prefix, CustomerInterface $customer)
{
$contact = $customer->getContact();
$address = $contact->getAddress();

$cryptData->add($prefix . 'Surname', $contact->getName()->getLastName());
$cryptData->add($prefix . 'Firstnames', $contact->getName()->getFirstName());
$cryptData->add($prefix . 'Address1', $address->getLine1());
$cryptData->add($prefix . 'Address2', $address->getLine2());
$cryptData->add($prefix . 'City', $address->getCity());
$cryptData->add($prefix . 'PostCode', $address->getPostCode()->get());
$cryptData->add($prefix . 'Country', $address->getCountry()->getCode());
}

/**
* @param OrderIntefface $order
* @return string
Expand All @@ -129,25 +154,11 @@ private function getCrypt(OrderInterface $order)
// @todo Get server name from the environment
->add(self::CRYPT_VAR_SUCCESS_URL, $this->getCallbackUrl('success'))
->add(self::CRYPT_VAR_FAILURE_URL, $this->getCallbackUrl('failure'))

// @todo Get this information from the user.
->add('BillingSurname', 'Bloggs')
->add('BillingFirstnames', 'Joe')
->add('BillingAddress1', 'Joes House')
//->add('BillingAddress2', '')
->add('BillingCity', 'Big Town')
->add('BillingPostCode', 'SA43 1JD')
->add('BillingCountry', 'GB')

->add('DeliverySurname', 'Bloggs')
->add('DeliveryFirstnames', 'Joe')
->add('DeliveryAddress1', 'Joes House')
//->add('BillingAddress2', '')
->add('DeliveryCity', 'Big Town')
->add('DeliveryPostCode', 'SA43 1JD')
->add('DeliveryCountry', 'GB')
;

$this->addContact($this->cryptData, 'Billing', $this->customer);
$this->addContact($this->cryptData, 'Delivery', $this->customer);

return $this->cipher->encrypt(
(string) $this->cryptData,
$this->options->getConnectionOptions()->getPassword()
Expand Down

0 comments on commit 3d1ce10

Please sign in to comment.