Skip to content

Commit 11ebdf2

Browse files
Add PaymentProcessor.Query and PaymentProcessor.RecurQuery
1 parent f1a9cd4 commit 11ebdf2

File tree

4 files changed

+137
-29
lines changed

4 files changed

+137
-29
lines changed

CRM/Core/Payment/OmnipayMultiProcessor.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,7 @@ public function handlePaymentNotification() {
801801
* @throws CiviCRM_API3_Exception
802802
*/
803803
public function processPaymentNotification($params) {
804-
$paymentProcessorTypeId = civicrm_api3('payment_processor', 'getvalue', array(
805-
'id' => $params['processor_id'],
806-
'return' => 'payment_processor_type_id',
807-
));
808-
$paymentProcessorTypeName = civicrm_api3('payment_processor_type', 'getvalue', array(
809-
'id' => $paymentProcessorTypeId,
810-
'return' => 'name',
811-
));
812-
$this->gateway = Omnipay::create(str_replace('omnipay_', '', $paymentProcessorTypeName));
813-
$this->setProcessorFields();
804+
$this->createGateway($params['processor_id']);
814805
$originalRequest = $_REQUEST;
815806
$_REQUEST = $params;
816807
$response = $this->gateway->completePurchase($params)->send();
@@ -864,6 +855,18 @@ public function processPaymentNotification($params) {
864855
$this->redirectOrExit('fail');
865856
}
866857

858+
public function queryPaymentPlans($params) {
859+
$this->createGateway($this->_paymentProcessor['id']);
860+
$response = $this->gateway->paymentPlanQuery($params)->send();
861+
return $response->getPlanData();
862+
}
863+
864+
public function query($params) {
865+
$this->createGateway($this->_paymentProcessor['id']);
866+
$response = $this->gateway->query($params)->send();
867+
return $response->getData();
868+
}
869+
867870
/**
868871
* Static wrapper for IPN / Payment response handling - this allows us to re-call from the api.
869872
*
@@ -1025,5 +1028,24 @@ public function getEditableRecurringScheduleFields() {
10251028
return $possibles;
10261029
}
10271030

1031+
/**
1032+
* @param int $id
1033+
*
1034+
* @throws \CRM_Core_Exception
1035+
* @throws \CiviCRM_API3_Exception
1036+
*/
1037+
private function createGateway($id) {
1038+
$paymentProcessorTypeId = civicrm_api3('payment_processor', 'getvalue', array(
1039+
'id' => $id,
1040+
'return' => 'payment_processor_type_id',
1041+
));
1042+
$paymentProcessorTypeName = civicrm_api3('payment_processor_type', 'getvalue', array(
1043+
'id' => $paymentProcessorTypeId,
1044+
'return' => 'name',
1045+
));
1046+
$this->gateway = Omnipay::create(str_replace('omnipay_', '', $paymentProcessorTypeName));
1047+
$this->setProcessorFields();
1048+
}
1049+
10281050
}
10291051

CRM/Core/Payment/processors.mgd.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,6 @@
181181
'payment_type' => 1,
182182
),
183183
),
184-
4 => array(
185-
'name' => 'OmniPay - Authorize AIM',
186-
'entity' => 'payment_processor_type',
187-
'params' =>
188-
array(
189-
'version' => 3,
190-
'title' => 'OmniPay - Authorize AIM',
191-
'name' => 'omnipay_AuthorizeNet_AIM',
192-
'description' => 'Omnipay OmniPay - Authorize AIM Payment Processor',
193-
'user_name_label' => 'Api Login ID',
194-
'password_label' => 'Transaction Key',
195-
'signature_label' => 'Hash Secret',
196-
'class_name' => 'Payment_OmnipayMultiProcessor',
197-
'url_site_default' => 'https://secure.authorize.net/gateway/transact.dll',
198-
'url_api_default' => 'https://secure.authorize.net/gateway/transact.dll',
199-
'billing_mode' => 1,
200-
'payment_type' => 1,
201-
),
202-
),
203184
5 => array(
204185
'name' => 'OmniPay - Authorize SIM',
205186
'entity' => 'payment_processor_type',
@@ -426,4 +407,22 @@
426407
'payment_type' => 1,
427408
),
428409
),
410+
16 => array(
411+
'name' => 'OmniPay - Authorize AIM',
412+
'entity' => 'payment_processor_type',
413+
'params' => array(
414+
'version' => 3,
415+
'title' => 'OmniPay - Authorize AIM',
416+
'name' => 'omnipay_AuthorizeNet_AIM',
417+
'description' => 'Omnipay OmniPay - Authorize AIM Payment Processor',
418+
'user_name_label' => 'Api Login ID',
419+
'password_label' => 'Transaction Key',
420+
'signature_label' => 'Hash Secret',
421+
'class_name' => 'Payment_OmnipayMultiProcessor',
422+
'url_site_default' => 'https://secure.authorize.net/gateway/transact.dll',
423+
'url_api_default' => 'https://secure.authorize.net/gateway/transact.dll',
424+
'billing_mode' => 1,
425+
'payment_type' => 1,
426+
),
427+
),
429428
);

api/v3/PaymentProcessor/Query.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Query Payment Processor recurring details.
5+
*
6+
* @param array $params
7+
*
8+
* @throws API_Exception
9+
* @throws CiviCRM_API3_Exception
10+
*
11+
* @return array
12+
* API Result array
13+
*/
14+
function civicrm_api3_payment_processor_query($params) {
15+
$processor = civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor_id']));
16+
$responder = new CRM_Core_Payment_OmnipayMultiProcessor('live', $processor);
17+
$result = $responder->query($params);
18+
$count = 0;
19+
foreach ($result as $id => $row) {
20+
try {
21+
civicrm_api3('ContributionRecur', 'getsingle', array('processor_id' => $row['id'],
22+
));
23+
}
24+
catch (Exception $e) {
25+
$count++;
26+
echo $count . " " . ($id+1) . " " . $row['id'] . " " . $row['firstName'] . " " . $row['lastName'] . "\n";
27+
}
28+
}
29+
30+
//return civicrm_api3_create_success($result, $params);
31+
}
32+
33+
/**
34+
* Define metadata for payment_processor.tokenquery.
35+
*
36+
* @param array $params
37+
*/
38+
function _civicrm_api3_payment_processor_query_spec(&$params) {
39+
$params['contribution_recur_id'] = array(
40+
'title' => 'Contribution Recur ID',
41+
'type' => CRM_Utils_Type::T_INT,
42+
);
43+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* Query Payment Processor recurring details.
5+
*
6+
* @param array $params
7+
*
8+
* @throws API_Exception
9+
* @throws CiviCRM_API3_Exception
10+
*
11+
* @return array
12+
* API Result array
13+
*/
14+
function civicrm_api3_payment_processor_recur_query($params) {
15+
$processor = civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor_id']));
16+
$responder = new CRM_Core_Payment_OmnipayMultiProcessor('live', $processor);
17+
$result = $responder->queryPaymentPlans($params);
18+
$count = 0;
19+
foreach ($result as $id => $row) {
20+
try {
21+
civicrm_api3('ContributionRecur', 'getsingle', array(
22+
'processor_id' => $row['id'],
23+
));
24+
}
25+
catch (Exception $e) {
26+
$count++;
27+
echo $count . " " . ($id+1) . " " . $row['id'] . " " . $row['firstName'] . " " . $row['lastName'] . "\n";
28+
}
29+
}
30+
31+
return civicrm_api3_create_success($result, $params);
32+
}
33+
34+
/**
35+
* Define metadata for payment_processor.tokenquery.
36+
*
37+
* @param array $params
38+
*/
39+
function _civicrm_api3_payment_processor_recur_query_spec(&$params) {
40+
$params['contribution_recur_id'] = array(
41+
'title' => 'Contribution Recur ID',
42+
'type' => CRM_Utils_Type::T_INT,
43+
);
44+
}

0 commit comments

Comments
 (0)