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

WIP: Allow for creation of recurring and adhoc subscriptions #15

Merged
merged 4 commits into from
Feb 2, 2018
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
113 changes: 109 additions & 4 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,66 @@ public function setCustomInt5($value)
return $this->setParameter('customInt5', $value);
}

public function getPaymentMethod()
{
return $this->getParameter('paymentMethod');
}

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

public function getSubscriptionType()
{
return $this->getParameter('subscriptionType');
}

public function getBillingDate()
{
return $this->getParameter('billingDate');
}

public function getRecurringAmount()
{
return $this->getParameter('recurringAmount');
}

public function getFrequency()
{
return $this->getParameter('frequency');
}

public function getCycles()
{
return $this->getParameter('cycles');
}

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

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

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

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

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

public function getData()
{
$this->validate('amount', 'description');
Expand Down Expand Up @@ -182,8 +242,30 @@ public function getData()
$data['custom_str4'] = $this->getCustomStr4();
$data['custom_str5'] = $this->getCustomStr5();

/**
* Allow overriding the Payment Method
*/
if ($this->getPaymentMethod()) {
$data['payment_method'] = $this->getPaymentMethod();
}

/**
* Subscription billing options.
*/
if (1 == $this->getSubscriptionType()) {
$data['subscription_type'] = $this->getSubscriptionType();
$data['billing_date'] = $this->getBillingDate();
$data['recurring_amount'] = $this->getRecurringAmount();
$data['frequency'] = $this->getFrequency();
$data['cycles'] = $this->getCycles();
}
if (2 == $this->getSubscriptionType()) {
$data['subscription_type'] = $this->getSubscriptionType();
}

$data['passphrase'] = $this->getParameter('passphrase');
$data['signature'] = $this->generateSignature($data);
unset($data['passphrase']);

return $data;
}
Expand All @@ -193,11 +275,34 @@ protected function generateSignature($data)
$fields = array();

// specific order required by PayFast
// @see https://developers.payfast.co.za/documentation/#checkout-page
foreach (array('merchant_id', 'merchant_key', 'return_url', 'cancel_url', 'notify_url', 'name_first',
'name_last', 'email_address', 'm_payment_id', 'amount', 'item_name', 'item_description',
'email_confirmation', 'confirmation_address', 'custom_int1', 'custom_int2', 'custom_int3',
'custom_int4', 'custom_int5', 'custom_str1', 'custom_str2', 'custom_str3', 'custom_str4',
'custom_str5', 'passphrase') as $key) {
'name_last', 'email_address', 'cell_number',
/**
* Transaction Details
*/
'm_payment_id', 'amount', 'item_name', 'item_description',
/**
* Custom return data
*/
'custom_int1', 'custom_int2', 'custom_int3', 'custom_int4', 'custom_int5',
'custom_str1', 'custom_str2', 'custom_str3', 'custom_str4', 'custom_str5',
/**
* Email confirmation
*/
'email_confirmation', 'confirmation_address',
/**
* Payment Method
*/
'payment_method',
/**
* Subscriptions
*/
'subscription_type', 'billing_date', 'recurring_amount', 'frequency', 'cycles',
/**
* Passphrase for md5 signature generation
*/
'passphrase') as $key) {
if (!empty($data[$key])) {
$fields[$key] = $data[$key];
}
Expand Down