DragonByte Tech
Well-known member
- Affected version
- 2.0.2
At the moment, there is no way for me to add additional parameters to the
Could you please change the code to the following:
So that it can be extended without issue?
Use case: I want to specify tax rate, which I could do by adding
Thanks!
Fillip
$params
array used in XF\Payment\PayPal
without overriding the entire initiatePayment
function.Could you please change the code to the following:
PHP:
/**
* @param Controller $controller
* @param PurchaseRequest $purchaseRequest
* @param Purchase $purchase
*
* @return array
*/
protected function _getParams(PurchaseRequest $purchaseRequest, Purchase $purchase)
{
$paymentProfile = $purchase->paymentProfile;
$purchaser = $purchase->purchaser;
$params = [
'business' => $paymentProfile->options['primary_account'],
'currency_code' => $purchase->currency,
'item_name' => $purchase->title,
'quantity' => 1,
'no_note' => 1,
// 2 = required, 1 = not required, 0 = optional
'no_shipping' => !empty($paymentProfile->options['require_address']) ? 2 : 1,
'custom' => $purchaseRequest->request_key,
'charset' => 'utf8',
'email' => $purchaser->email,
'return' => $purchase->returnUrl,
'cancel_return' => $purchase->cancelUrl,
'notify_url' => $this->getCallbackUrl()
];
if ($purchase->recurring)
{
$params['cmd'] = '_xclick-subscriptions';
$params['a3'] = $purchase->cost;
$params['p3'] = $purchase->lengthAmount;
switch ($purchase->lengthUnit)
{
case 'day': $params['t3'] = 'D'; break;
case 'month': $params['t3'] = 'M'; break;
case 'year': $params['t3'] = 'Y'; break;
default: $params['t3'] = ''; break;
}
$params['src'] = 1;
$params['sra'] = 1;
}
else
{
$params['cmd'] = '_xclick';
$params['amount'] = $purchase->cost;
}
return $params;
}
/**
* @param Controller $controller
* @param PurchaseRequest $purchaseRequest
* @param Purchase $purchase
*
* @return mixed
*/
public function initiatePayment(Controller $controller, PurchaseRequest $purchaseRequest, Purchase $purchase)
{
$params = $this->_getParams($purchaseRequest, $purchase);
$endpointUrl = $this->getApiEndpoint();
$endpointUrl .= '?' . http_build_query($params);
return $controller->redirect($endpointUrl, '');
}
Use case: I want to specify tax rate, which I could do by adding
$params['tax'] = '50.00';
(flat rate) or $params['tax_rate'] = '13.00';
(percent), but I have to destroy the work of anyone else also extending the same function just to add this variable.Thanks!
Fillip
Last edited: