/** * Process payment by sending payment info to Paytrail with REST API. * * @param array $params name value pair of Payment processor data * @param string $component name of CiviCRM component that is using this Payment Processor (contribute or event) * @param string $merchantId Paytrail merchant id * @param string $merchantSecret Paytrail merchant secret * @return Verkkomaksut_Module_Rest_Result REST call result with redirect URL and token */ public function processPayment(&$params, $component, $merchantId, $merchantSecret) { $this->paytrailConfig->setPaymentProcessorParams($params); if ($component != 'contribute' && $component != 'event') { CRM_Core_Error::fatal(ts('Component is invalid')); } // Create payment. Default Paytrail API mode is E1. $payment =& $this->createPaymentObject($params, $component); $payment->setLocale($this->paytrailConfig->get('locale')); // Send request to https://payment.verkkomaksut.fi with Merchant ID and Merchant secret $module = new Verkkomaksut_Module_Rest($merchantId, $merchantSecret); try { $result = $module->processPayment($payment); } catch (Verkkomaksut_Exception $e) { CRM_Core_Error::fatal("Error contacting Paytrail: " . $e->getMessage() . ". Order number: " . $params['invoiceID']); exit; } return $result; }