diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index ccb3017..1272c23 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -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'); @@ -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; } @@ -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]; }