forked from henare/CiviCRM-eWay-recurring-payment-processor
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ewayrecurring.php
130 lines (115 loc) · 3.35 KB
/
ewayrecurring.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
require_once 'ewayrecurring.civix.php';
require_once 'nusoap.php';
/**
* Implementation of hook_civicrm_config
*
* @param $config
*/
function ewayrecurring_civicrm_config(&$config) {
_ewayrecurring_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_install
*/
function ewayrecurring_civicrm_install() {
return _ewayrecurring_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_enable
*/
function ewayrecurring_civicrm_enable() {
return _ewayrecurring_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_managed
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @param $entities
*/
function ewayrecurring_civicrm_managed(&$entities) {
try {
//handling for versions where job.create api does not exist
civicrm_api3('job', 'create', array());
}
catch (Exception $e) {
if (stristr($e->getMessage(), 'does not exist')) {
return;
}
}
return;
}
/**
* Implements hook_civicrm_navigationMenu().
*
* Adds eway settings page to the navigation menu.
*
* @param array $menu
*/
function ewayrecurring_civicrm_navigationMenu(&$menu) {
_ewayrecurring_civix_insert_navigation_menu($menu, 'Administer', [
'label' => 'Eway',
'name' => 'eway',
'url' => 'civicrm/settings/eway',
'permission' => 'administer CiviCRM',
]);
}
/**
* Implements hook_civicrm_buildForm().
*
* Set default credit card values when in test mode.
*
* @param string $formName
* @param CRM_Contribute_Form_Contribution|CRM_Event_Form_Participant $form
*/
function ewayrecurring_civicrm_buildForm($formName, &$form) {
$formWhiteList = array('CRM_Contribute_Form_Contribution', 'CRM_Event_Form_Participant');
if (!in_array($formName, $formWhiteList)) {
return;
}
//CRM_Core_Resources::singleton()->addScriptUrl('https://secure.ewaypayments.com/scripts/eCrypt.js');
if (!$form->_mode == 'live' || (!civicrm_api3('setting', 'getvalue', array(
'group' => 'eway',
'name' => 'eway_developer_mode'
)))) {
return;
}
if (!isEwayOnlyRelevantProcessor($form)) {
return;
}
CRM_Core_Session::setStatus(ts('Eway is in test mode. Test credentials have been pre-filled. No live transaction will be submitted'));
$defaults['credit_card_number'] = '4444333322221111';
$defaults['credit_card_type'] = 'Visa';
$defaults['cvv2'] = '567';
$defaults['credit_card_exp_date[Y]'] = 21;
$defaults['credit_card_exp_date[M]'] = '1';
$defaults['credit_card_exp_date'] = array('M' => 1, 'Y' => 2021);
$form->setDefaults($defaults);
}
/**
* Is eway the only relevant processor on this form.
*
* If eWay is the default or the only possible type on this form we can fill in the
* default credit card values.
*
* @param CRM_Core_Form $form
*
* @return bool
*/
function isEwayOnlyRelevantProcessor(&$form) {
if (($processors = array_keys($form->_processors)) == FALSE) {
return FALSE;
}
$processors = civicrm_api3('PaymentProcessor', 'get', array('id' => array('IN' => $processors)));
if (isset($form->_paymentProcessor) && $processors['values'][$form->_paymentProcessor['id']]['class_name'] == 'Payment_Ewayrecurring') {
return TRUE;
}
foreach ($processors['values'] as $processorID => $processorSpec) {
if ($processorSpec['class_name'] != 'Payment_Ewayrecurring') {
return FALSE;
}
}
return TRUE;
}