$result = $this->invokeAPI($args);
- if (is_a($result, 'CRM_Core_Error')) {
- throw new PaymentProcessorException($result->message);
- }
-
/* Success */
return $result['token'];
$result = $this->invokeAPI($args);
- if (is_a($result, 'CRM_Core_Error')) {
- throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
- }
-
/* Success */
$fieldMap = [
'token' => 'token',
'payer_status' => 'payerstatus',
'payer_id' => 'payerid',
- 'first_name' => 'firstname',
- 'middle_name' => 'middlename',
- 'last_name' => 'lastname',
+ 'billing_first_name' => 'firstname',
+ 'billing_middle_name' => 'middlename',
+ 'billing_last_name' => 'lastname',
'street_address' => 'shiptostreet',
'supplemental_address_1' => 'shiptostreet2',
'city' => 'shiptocity',
$result = $this->invokeAPI($args);
- if (is_a($result, 'CRM_Core_Error')) {
- throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
- }
-
/* Success */
$params['trxn_id'] = $result['transactionid'];
$params['gross_amount'] = $result['amt'];
$result = $this->invokeAPI($args);
- if (is_a($result, 'CRM_Core_Error')) {
- return $result;
- }
-
/* Success - result looks like"
* array (
* 'profileid' => 'I-CP1U0PLG91R2',
$result = $this->invokeAPI($args);
- // WAG
- if (is_a($result, 'CRM_Core_Error')) {
- return $result;
- }
-
$params['recurr_profile_id'] = NULL;
if (CRM_Utils_Array::value('is_recur', $params) == 1) {
* @param string $message
* @param array $params
*
- * @return array|bool|object
+ * @return bool
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function cancelSubscription(&$message = '', $params = []) {
$args['NOTE'] = CRM_Utils_Array::value('reason', $params);
$result = $this->invokeAPI($args);
- if (is_a($result, 'CRM_Core_Error')) {
- return $result;
- }
+
$message = "{$result['ack']}: profileid={$result['profileid']}";
return TRUE;
}
$args['ZIP'] = $params['country'];
$result = $this->invokeAPI($args);
- if (is_a($result, 'CRM_Core_Error')) {
- return $result;
- }
+
$message = "{$result['ack']}: profileid={$result['profileid']}";
return TRUE;
}
* @param string $message
* @param array $params
*
- * @return array|bool|object
+ * @return bool
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function changeSubscriptionAmount(&$message = '', $params = []) {
$result = $this->invokeAPI($args);
CRM_Core_Error::debug_var('$result', $result);
- if (is_a($result, 'CRM_Core_Error')) {
- return $result;
- }
+
$message = "{$result['ack']}: profileid={$result['profileid']}";
return TRUE;
}
* returns an associative array containing the response from the server.
*
* @param array $args
- * @param null $url
*
* @return array|object
- * @throws \Exception
+ * @throws \Civi\Payment\Exception\PaymentProcessorException
*/
- public function invokeAPI($args, $url = NULL) {
-
- if ($url === NULL) {
- if (empty($this->_paymentProcessor['url_api'])) {
- CRM_Core_Error::fatal(ts('Please set the API URL. Please refer to the documentation for more details'));
- }
+ public function invokeAPI($args) {
- $url = $this->_paymentProcessor['url_api'] . 'nvp';
+ if (empty($this->_paymentProcessor['url_api'])) {
+ throw new PaymentProcessorException(ts('Please set the API URL. Please refer to the documentation for more details'));
}
+ $url = $this->_paymentProcessor['url_api'] . 'nvp';
+
$p = [];
foreach ($args as $n => $v) {
$p[] = "$n=" . urlencode($v);
$nvpreq = implode('&', $p);
if (!function_exists('curl_init')) {
- CRM_Core_Error::fatal("curl functions NOT available.");
+ throw new PaymentProcessorException('curl functions NOT available.');
}
//setting the curl parameters.
$result = self::deformat($response);
if (curl_errno($ch)) {
- $e = CRM_Core_Error::singleton();
- $e->push(curl_errno($ch),
- 0, NULL,
- curl_error($ch)
- );
- return $e;
- }
- else {
- curl_close($ch);
+ throw new PaymentProcessorException(ts('Network error') . ' ' . curl_error($ch) . curl_errno($ch), curl_errno($ch));
}
+ curl_close($ch);
$outcome = strtolower(CRM_Utils_Array::value('ack', $result));