Permalink
Browse files

Trying to create inheritance

More work
Working now
Moved child classes to sub directory
More updates
More work on payment profile
New partner property paymentProfileType
  • Loading branch information...
1 parent c0ac76a commit 491edb612722cf70608f39bf4845a918d9223475 @jcroll jcroll committed with iampersistent Jan 25, 2013
@@ -9,6 +9,7 @@
namespace Vespolina\Entity\Partner;
use Doctrine\Common\Collections\ArrayCollection;
+use Vespolina\Entity\Partner\PaymentProfileInterface;
/**
* Implementation of PartnerInterface
@@ -38,21 +39,30 @@ class Partner implements PartnerInterface
protected $primaryContact;
protected $roles;
protected $type;
- protected $payByCreditCard = true;
protected $paymentProfile;
+ protected $paymentProfileType;
+
+ public function setPaymentProfileType($paymentProfileType)
+ {
+ $this->paymentProfileType = $paymentProfileType;
+ }
+
+ public function getPaymentProfileType()
+ {
+ return $this->paymentProfileType;
+ }
public function __construct()
{
$this->addresses = new ArrayCollection();
- $this->paymentProfile = new PaymentProfile();
}
public function getId()
{
return $this->id;
}
- public function setPaymentProfile($paymentProfile)
+ public function setPaymentProfile(PaymentProfileInterface $paymentProfile)
{
$this->paymentProfile = $paymentProfile;
@@ -325,14 +335,4 @@ public function setOrganisationDetails($organisationDetails)
return $this;
}
-
- public function setPayByCreditCard($payByCreditCard)
- {
- $this->payByCreditCard = $payByCreditCard;
- }
-
- public function isPayByCreditCard()
- {
- return $this->payByCreditCard;
- }
}
View
@@ -2,32 +2,61 @@
namespace Vespolina\Entity\Partner;
-class PaymentProfile
+use Vespolina\Entity\Partner\PartnerInterface;
+
+class PaymentProfile implements PaymentProfileInterface
{
+ const PAYMENT_PROFILE_TYPE_CREDIT_CARD = 'Credit Card';
+ const PAYMENT_PROFILE_TYPE_INVOICE = 'Invoice';
+
+ public static $validTypes = array(
+ self::PAYMENT_PROFILE_TYPE_CREDIT_CARD,
+ self::PAYMENT_PROFILE_TYPE_INVOICE,
+ );
+
protected $id;
protected $reference;
- protected $last4digits;
+ protected $partner;
- public function getId()
+ /**
+ * @inheritdoc
+ */
+ public function setPartner(PartnerInterface $partner)
{
- return $this->id;
+ $this->partner = $partner;
+
+ return $this;
}
- public function setLast4digits($last4digits)
+ /**
+ * @inheritdoc
+ */
+ public function getPartner()
{
- $this->last4digits = $last4digits;
+ return $this->partner;
}
- public function getLast4digits()
+ /**
+ * @inheritdoc
+ */
+ public function getId()
{
- return $this->last4digits;
+ return $this->id;
}
+ /**
+ * @inheritdoc
+ */
public function setReference($reference)
{
$this->reference = $reference;
+
+ return $this;
}
+ /**
+ * @inheritdoc
+ */
public function getReference()
{
return $this->reference;
@@ -0,0 +1,18 @@
+<?php
+
+namespace Vespolina\Entity\Partner;
+
+use Vespolina\Entity\Partner\PartnerInterface;
+
+interface PaymentProfileInterface
+{
+ function setPartner(PartnerInterface $partner);
+
+ function getPartner();
+
+ function getId();
+
+ function setReference($reference);
+
+ function getReference();
+}
@@ -0,0 +1,101 @@
+<?php
+
+namespace Vespolina\Entity\Partner\PaymentProfileType;
+
+use Vespolina\Entity\Partner\PaymentProfile;
+
+class CreditCard extends PaymentProfile implements PaymentProfileTypeInterface
+{
+ protected $activeCardNumber;
+ protected $address;
+ protected $cardType;
+ protected $expiration;
+ protected $persistedCardNumber;
+
+ /**
+ * @param string $address
+ * @return \Vespolina\Entity\CreditCardProfile
+ */
+ public function setAddress($address)
+ {
+ $this->address = $address;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getAddress()
+ {
+ return $this->address;
+ }
+
+ /**
+ * @param string $cardNumber
+ * @return \Vespolina\Entity\CreditCardProfile
+ */
+ public function setCardNumber($cardNumber)
+ {
+ $this->activeCardNumber = preg_replace('/\D/', '', $cardNumber);
+ $chars = strlen($this->activeCardNumber);
+ $this->persistedCardNumber = str_repeat('*', $chars - 4) . substr($this->activeCardNumber, -4);
+
+ return $this;
+ }
+
+ /**
+ * @param null $type
+ * @return mixed
+ */
+ public function getCardNumber($type = null)
+ {
+ if ($type === 'active') {
+ return $this->activeCardNumber;
+ }
+ return $this->persistedCardNumber;
+ }
+
+ /**
+ * @param $cardType
+ * @return \Vespolina\Entity\CreditCardProfile
+ */
+ public function setCardType($cardType)
+ {
+ $this->cardType = $cardType;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getCardType()
+ {
+ return $this->cardType;
+ }
+
+ /**
+ * @param \DateTime
+ * @return \Vespolina\Entity\CreditCardProfile
+ */
+ public function setExpiration(\DateTime $expirationDate)
+ {
+ $this->expiration = $expirationDate;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getExpiration()
+ {
+ return $this->expiration;
+ }
+
+ public function getType()
+ {
+ return 'Credit Card';
+ }
+}
@@ -0,0 +1,13 @@
+<?php
+
+namespace Vespolina\Entity\Partner\PaymentProfileType;
+
+use Vespolina\Entity\Partner\PaymentProfile;
+
+class Invoice extends PaymentProfile implements PaymentProfileTypeInterface
+{
+ public function getType()
+ {
+ return 'Invoice';
+ }
+}
@@ -0,0 +1,8 @@
+<?php
+
+namespace Vespolina\Entity\Partner\PaymentProfileType;
+
+interface PaymentProfileTypeInterface
+{
+ function getType();
+}
@@ -5,22 +5,12 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Vespolina\Entity\Partner\PaymentProfile;
class PartnerType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
- if ($options['is_admin']) {
- $builder
- ->add('payByCreditCard', 'choice', array(
- 'label' => 'Payment Method',
- 'choices' => array(1 => 'Credit', 0 => 'Invoice'),
- 'multiple' => false,
- 'expanded' => true,
- ))
- ;
- }
-
$builder
->add('name')
->add('type')
@@ -40,8 +30,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'attr' => array('class' => 'license-box')
)
))
+ ->add('paymentProfileType', 'choice', array(
+ 'label' => 'Payment Method',
+ 'choices' => array_combine(PaymentProfile::$validTypes, PaymentProfile::$validTypes),
+ 'required' => true,
+ 'multiple' => false,
+ 'expanded' => true,
+ ))
;
+ if (isset($options['paymentProfileFormTypeClass'])) {
+ $builder->add('paymentProfile', new $options['paymentProfileFormTypeClass']);
+ }
}
/**
@@ -50,7 +50,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Vespolina\Entity\Partner\Partner',
- 'is_admin' => false
+ 'paymentProfileFormTypeClass' => false
));
}
@@ -0,0 +1,39 @@
+<?php
+
+namespace Vespolina\Form\Partner;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+class PaymentProfileCreditCardType extends AbstractType
+{
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $builder
+ ->add('address')
+ ->add('expiration', 'date', array(
+ 'days' => array(1),
+ ))
+ ->add('cardType')
+ ->add('cardNumber')
+ ;
+ }
+
+ /**
+ * @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
+ */
+ public function setDefaultOptions(OptionsResolverInterface $resolver) {
+ $resolver->setDefaults(array(
+ 'data_class' => 'Vespolina\Entity\Partner\PaymentProfileType\CreditCard'
+ ));
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return 'vespolina_partner_payment_profile_credit_card';
+ }
+}
Oops, something went wrong.

0 comments on commit 491edb6

Please sign in to comment.