Skip to content

Ensure validate params get through to preapprove function #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CRM/Core/Payment/OmnipayMultiProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ public function buildForm(&$form) {
'paymentProcessorId' => $this->_paymentProcessor['id'], 'currency' => $form->getCurrency(),
'is_test' => $this->_is_test,
'title' => $form->getTitle(),
'validate' => [],
];
if (is_a($form, 'CRM_Contribute_Form_Contribution_Main')) {
$jsVariables['validate'] = ['entity' => 'ContributionPage', 'params' => ['id' => $form->_id, 'action' => 'submit']];
}
$clientSideCredentials = $this->getProcessorTypeMetadata('client_side_credentials');
if ($clientSideCredentials) {
foreach ($clientSideCredentials as $key => $clientSideKey) {
Expand Down
2 changes: 2 additions & 0 deletions Metadata/js/omnipay_PaypalRest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
var paymentAmount = calculateTotalFee();
var isRecur = $('#is_recur').is(":checked");
var recurText = isRecur ? ' recurring' : '';
var validate = CRM.vars.omnipay.validate;

return new Promise(function (resolve, reject) {
CRM.api3('PaymentProcessor', 'preapprove', {
Expand All @@ -24,6 +25,7 @@
'frequency_unit' : frequencyUnit,
'frequency_interval' : frequencyInterval,
'description' : CRM.vars.omnipay.title + ' ' + CRM.formatMoney(paymentAmount) + recurText,
'validate' : validate,
}
).then(function (result) {
if (result['is_error'] === 1) {
Expand Down
4 changes: 4 additions & 0 deletions api/v3/PaymentProcessor/Preapprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @throws CiviCRM_API3_Exception
*/
function civicrm_api3_payment_processor_preapprove($params) {
if (!empty($params['validate'])) {
$validation = civicrm_api3($params['validate']['entity'], 'validate', array_merge($params['validate']['params'], $params));
// @todo - do something clever if it fails
}
$processor = Civi\Payment\System::singleton()->getById($params['payment_processor_id']);
$processor->setPaymentProcessor(civicrm_api3('PaymentProcessor', 'getsingle', array('id' => $params['payment_processor_id'])));
$result = $processor->doPreApproval($params);
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/api/PreApproveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function testPreApproveRest() {
'component' => 'contribute',
'version' => 3,
'email' => '[email protected]',
'validate' => []
])['values'][0];
$this->assertEquals('EC-9T988732661526452', $preApproval['token']);

Expand Down