Skip to content
Open
Show file tree
Hide file tree
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
57 changes: 49 additions & 8 deletions src/OpenBuildings/PayPal/Payment/Adaptive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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');
Expand All @@ -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;
}
}

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/OpenBuildings/PayPal/Payment/Adaptive/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down