From 87d7738c453cabc6c5815ffbea2c52b9cdf8b742 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Mon, 15 Jul 2013 19:45:42 +0300 Subject: [PATCH] correct payment_type setting --- src/OpenBuildings/PayPal/Payment/Adaptive.php | 57 ++++++++++++++++--- .../PayPal/Payment/Adaptive/Parallel.php | 2 +- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/OpenBuildings/PayPal/Payment/Adaptive.php b/src/OpenBuildings/PayPal/Payment/Adaptive.php index d2452e4..d5781ff 100644 --- a/src/OpenBuildings/PayPal/Payment/Adaptive.php +++ b/src/OpenBuildings/PayPal/Payment/Adaptive.php @@ -79,11 +79,16 @@ class Payment_Adaptive extends Payment { ); protected static $_allowed_payment_types = array( + self::PAYMENT_TYPE_GOODS, + self::PAYMENT_TYPE_SERVICE, + self::PAYMENT_TYPE_PERSONAL, + self::PAYMENT_TYPE_CASHADVANCE, + self::PAYMENT_TYPE_DIGITALGOODS, + self::PAYMENT_TYPE_BANK_MANAGED_WITHDRAWAL, ); protected static $_allowed_fees_payer_types = array( self::FEES_PAYER_SENDER, - self::FEES_PAYER_PRIMARYRECEIVER, self::FEES_PAYER_EACHRECEIVER, ); @@ -128,6 +133,16 @@ public static function ap_api_url($method = NULL) protected $_action_type = 'PAY'; + public function __construct(array $config = array()) + { + parent::__construct($config); + + if ($fees_payer = $this->config('fees_payer')) + { + $this->fees_payer($fees_payer); + } + } + /** * NVP fields required for the Pay API operation */ @@ -166,8 +181,8 @@ public function fields() } if ( ! in_array($this->config('fees_payer'), Payment_Adaptive::$_allowed_fees_payer_types)) - throw new Exception('Fees payer type ":feesPayer" is not allowed!', array( - ':feesPayer' => $this->config('fees_payer') + throw new Exception('Fees payer type ":fees_payer" is not allowed!', array( + ':fees_payer' => $this->config('fees_payer') )); $fields['feesPayer'] = $this->config('fees_payer'); @@ -182,13 +197,19 @@ public function fields() $fields['ipnNotificationUrl'] = $this->notify_url(); } - if (($payment_type = $this->config('payment_type'))) + if (($payment_type = $this->config('payment_type')) + AND (is_string($payment_type) OR is_array($payment_type))) { - if (is_string($payment_type) - OR (is_array($payment_type) - AND ! empty($payment_type['primary']))) + $payment_type = (is_string($payment_type)) + ? $payment_type + : (( ! empty($payment_type['primary'])) + ? $payment_type['primary'] + : FALSE + ); + + if ($payment_type) { - $fields['receiverList'][0]['paymentType'] = $payment_type['primary']; + $fields['receiverList'][0]['paymentType'] = $payment_type; } } @@ -215,11 +236,31 @@ public function action_type($action_type = NULL) if ($action_type === NULL) return $this->_action_type; + if ( ! in_array($action_type, self::$_allowed_action_types)) + throw new Exception('Action type ":action_type" is not allowed!', array( + ':action_type' => $action_type + )); + $this->_action_type = $action_type; return $this; } + public function fees_payer($fees_payer = NULL) + { + if ($fees_payer === NULL) + return $this->_fees_payer; + + if ( ! in_array($fees_payer, self::$_allowed_fees_payer_types)) + throw new Exception('Fees payer type ":fees_payer" is not allowed!', array( + ':fees_payer' => $fees_payer + )); + + $this->_fees_payer = $fees_payer; + + return $this; + } + public function do_payment() { $fields = $this->fields(); diff --git a/src/OpenBuildings/PayPal/Payment/Adaptive/Parallel.php b/src/OpenBuildings/PayPal/Payment/Adaptive/Parallel.php index 475d64e..7f077b8 100644 --- a/src/OpenBuildings/PayPal/Payment/Adaptive/Parallel.php +++ b/src/OpenBuildings/PayPal/Payment/Adaptive/Parallel.php @@ -21,7 +21,7 @@ public function fields() { $payment_type = (is_string($payment_type)) ? $payment_type - : ((isset($payment_type['secondary']) AND $payment_type['secondary']) + : ( ! empty($payment_type['secondary']) ? $payment_type['secondary'] : FALSE );