Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #145, Resolves #147 #150

Merged
merged 1 commit into from
Nov 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions code/GatewayFieldsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,52 @@ public function getCardFields()
$months = array();
//generate list of months
for ($x = 1; $x <= 12; $x++) {
$months[$x] = date('m - F', mktime(0, 0, 0, $x, 1));
// Fixes #145 - Thanks to @digitall-it
$months[$x] = str_pad($x, 2, '0', STR_PAD_LEFT) . " - " . strftime('%B', mktime(0, 0, 0, $x));
}
$year = date('Y');
$range = 5;
$startrange = range(date('Y', strtotime("-$range years")), $year);
$expiryrange = range($year, date('Y', strtotime("+$range years")));

$fields = array(
'type' => \DropdownField::create($this->getFieldName('type'), _t('PaymentForm.Type', 'Type'), $this->getCardTypes()),
'name' => \TextField::create($this->getFieldName('name'), _t('PaymentForm.Name', 'Name on Card')),
'number' => \TextField::create($this->getFieldName('number'), _t('PaymentForm.Number', 'Card Number'))
->setDescription(_t('PaymentForm.NumberDescription', 'no dashes or spaces')),
'startMonth' => \DropdownField::create($this->getFieldName('startMonth'), _t('PaymentForm.StartMonth', 'Month'), $months),
'startYear' => \DropdownField::create($this->getFieldName('startYear'), _t('PaymentForm.StartYear', 'Year'),
array_combine($startrange, $startrange), $year
),
'expiryMonth' => \DropdownField::create($this->getFieldName('expiryMonth'), _t('PaymentForm.ExpiryMonth', 'Month'), $months),
'expiryYear' => \DropdownField::create($this->getFieldName('expiryYear'), _t('PaymentForm.ExpiryYear', 'Year'),
array_combine($expiryrange, $expiryrange), $year
),
'cvv' => \TextField::create($this->getFieldName('cvv'), _t('PaymentForm.CVV', 'Security Code'))
'type' => \DropdownField::create($this->getFieldName('type'), _t('PaymentForm.Type', 'Type'), $this->getCardTypes()),
'name' => \TextField::create($this->getFieldName('name'), _t('PaymentForm.Name', 'Name on Card')),
'number' => \TextField::create($this->getFieldName('number'), _t('PaymentForm.Number', 'Card Number'))
->setDescription(_t('PaymentForm.NumberDescription', 'no dashes or spaces')),
'startMonth' => \DropdownField::create(
$this->getFieldName('startMonth'),
_t('PaymentForm.StartMonth', 'Month'),
$months
)
->setHasEmptyDefault(true)
->setEmptyString(_t('PaymentForm.StartMonthDefaultText', 'Please Select ...')),
'startYear' => \DropdownField::create(
$this->getFieldName('startYear'),
_t('PaymentForm.StartYear', 'Year'),
array_combine($startrange, $startrange),
$year
)
->setHasEmptyDefault(true)
->setEmptyString(_t('PaymentForm.StartYearDefaultText', 'Please Select ...')),
'expiryMonth' => \DropdownField::create(
$this->getFieldName('expiryMonth'),
_t('PaymentForm.ExpiryMonth', 'Month'),
$months
)
->setHasEmptyDefault(true)
->setEmptyString(_t('PaymentForm.ExpiryMonthDefaultText', 'Please Select ...')),
'expiryYear' => \DropdownField::create(
$this->getFieldName('expiryYear'),
_t('PaymentForm.ExpiryYear', 'Year'),
array_combine($expiryrange, $expiryrange),
$year
)
->setHasEmptyDefault(true)
->setEmptyString(_t('PaymentForm.ExpiryYearDefaultText', 'Please Select ...')),
'cvv' => \TextField::create($this->getFieldName('cvv'), _t('PaymentForm.CVV', 'Security Code'))
->setMaxLength(5),
'issueNumber' => \TextField::create($this->getFieldName('issueNumber'), _t('PaymentForm.IssueNumber', 'Issue Number'))
'issueNumber' => \TextField::create($this->getFieldName('issueNumber'), _t('PaymentForm.IssueNumber', 'Issue Number'))
);

$this->cullForGateway($fields);
Expand Down Expand Up @@ -160,11 +183,11 @@ public function getBillingFields()
$fields = array(
'billingAddress1' => \TextField::create($this->getFieldName('billingAddress1'), _t('PaymentForm.BillingAddress1', 'Address')),
'billingAddress2' => \TextField::create($this->getFieldName('billingAddress2'), _t('PaymentForm.BillingAddress2', 'Address line 2')),
'city' => \TextField::create($this->getFieldName('billingCity'), _t('PaymentForm.BillingCity', 'City')),
'postcode' => \TextField::create($this->getFieldName('billingPostcode'), _t('PaymentForm.BillingPostcode', 'Postcode')),
'state' => \TextField::create($this->getFieldName('billingState'), _t('PaymentForm.BillingState', 'State')),
'country' => \TextField::create($this->getFieldName('billingCountry'), _t('PaymentForm.BillingCountry', 'Country')),
'phone' => \PhoneNumberField::create($this->getFieldName('billingPhone'), _t('PaymentForm.BillingPhone', 'Phone'))
'city' => \TextField::create($this->getFieldName('billingCity'), _t('PaymentForm.BillingCity', 'City')),
'postcode' => \TextField::create($this->getFieldName('billingPostcode'), _t('PaymentForm.BillingPostcode', 'Postcode')),
'state' => \TextField::create($this->getFieldName('billingState'), _t('PaymentForm.BillingState', 'State')),
'country' => \TextField::create($this->getFieldName('billingCountry'), _t('PaymentForm.BillingCountry', 'Country')),
'phone' => \PhoneNumberField::create($this->getFieldName('billingPhone'), _t('PaymentForm.BillingPhone', 'Phone'))
);
$this->cullForGateway($fields);

Expand All @@ -184,11 +207,11 @@ public function getShippingFields()
'shippingAddress2' => \TextField::create(
$this->getFieldName('shippingAddress2'), _t('PaymentForm.ShippingAddress2', 'Shipping Address 2')
),
'city' => \TextField::create($this->getFieldName('shippingCity'), _t('PaymentForm.ShippingCity', 'Shipping City')),
'city' => \TextField::create($this->getFieldName('shippingCity'), _t('PaymentForm.ShippingCity', 'Shipping City')),
'postcode' => \TextField::create($this->getFieldName('shippingPostcode'), _t('PaymentForm.ShippingPostcode', 'Shipping Postcode')),
'state' => \TextField::create($this->getFieldName('shippingState'), _t('PaymentForm.ShippingState', 'Shipping State')),
'country' => \TextField::create($this->getFieldName('shippingCountry'), _t('PaymentForm.ShippingCountry', 'Shipping Country')),
'phone' => \PhoneNumberField::create($this->getFieldName('shippingPhone'), _t('PaymentForm.ShippingPhone', 'Shipping Phone'))
'state' => \TextField::create($this->getFieldName('shippingState'), _t('PaymentForm.ShippingState', 'Shipping State')),
'country' => \TextField::create($this->getFieldName('shippingCountry'), _t('PaymentForm.ShippingCountry', 'Shipping Country')),
'phone' => \PhoneNumberField::create($this->getFieldName('shippingPhone'), _t('PaymentForm.ShippingPhone', 'Shipping Phone'))
);
$this->cullForGateway($fields);

Expand Down