This repository has been archived by the owner on Jun 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add settings page, include forceRecurring, implement forceRecurring fix
- Loading branch information
Rich Lott / Artful Robot
committed
Nov 18, 2020
1 parent
eddc0b2
commit 0fd2d59
Showing
13 changed files
with
354 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
// This file declares an Angular module which can be autoloaded | ||
// in CiviCRM. See also: | ||
// \https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules/n | ||
return [ | ||
'js' => [ | ||
'ang/gocardless.js', | ||
'ang/gocardless/*.js', | ||
'ang/gocardless/*/*.js', | ||
], | ||
'css' => [ | ||
'ang/gocardless.css', | ||
], | ||
'partials' => [ | ||
'ang/gocardless', | ||
], | ||
'requires' => [ | ||
'crmUi', | ||
'crmUtil', | ||
'ngRoute', | ||
], | ||
'settings' => [], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* Add any CSS rules for Angular module "gocardless" */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(function(angular, $, _) { | ||
// Declare a list of dependencies. | ||
angular.module('gocardless', CRM.angRequires('gocardless')); | ||
})(angular, CRM.$, CRM._); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<div class="crm-container"> | ||
<h1 crm-page-title>{{ts('GoCardless settings')}}</h1> | ||
|
||
<form name="myForm" crm-ui-id-scope> | ||
<!-- | ||
<div class="help"> | ||
<p>{{ts('This is an auto-generated skeletal page.')}}</p> | ||
<p>{{ts('To view more debugging information, edit the URL and include "?angularDebug=1".')}}</p> | ||
</div> | ||
<div crm-ui-accordion="{title: ts('Greeting')}"> | ||
<p ng-show="$ctrl.myContact.first_name">{{ ts('Hello, %1.', {1: $ctrl.myContact.first_name}) }}</p> | ||
<p ng-show="!$ctrl.myContact.first_name">{{ ts('Hello, stranger.') }}</p> | ||
</div> | ||
--> | ||
<div class="crm-block"> | ||
<div class="crm-group"> | ||
<label> | ||
<input | ||
type="checkbox" | ||
crm-ui-id="myForm.forceRecurring" | ||
name="forceRecurring" | ||
ng-model="gcSettings.forceRecurring" | ||
class="crm-form-checkbox" | ||
/> | ||
{{ts('Force recurring contributions when a GoCardless payment processor is chosen')}} | ||
</label> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<button ng-click="$ctrl.save()">{{ts('Save')}}</button> | ||
</div> | ||
<h2>Active Payment processors</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Test Webhook endpoint URL</th> | ||
<th>Live Webhook endpoint URL</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr ng-repeat="pp in ppTable" > | ||
<td>{{pp.name}}</td> | ||
<td><input type="text" value="{{pp.urlTest}}"/></td> | ||
<td><input type="text" value="{{pp.urlLive}}"/></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
</form> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
(function(angular, $, _) { | ||
|
||
angular.module('gocardless').config(function($routeProvider) { | ||
$routeProvider.when('/gocardless', { | ||
controller: 'GocardlessGoCardlessSettings', | ||
controllerAs: '$ctrl', | ||
templateUrl: '~/gocardless/GoCardlessSettings.html', | ||
|
||
// If you need to look up data when opening the page, list it out | ||
// under "resolve". | ||
resolve: { | ||
various: function(crmApi4) { | ||
return crmApi4({ | ||
gcSettings: ['Setting', 'get', {select: ['gocardless']}, 0], | ||
paymentProcessors: ['PaymentProcessor', 'get', { | ||
where: [ | ||
["payment_processor_type_id:name", '=', 'GoCardless'], | ||
["is_test", 'IS NOT NULL'], // api4 seems to skip test ones otherwise | ||
], | ||
orderBy: { | ||
is_active: 'DESC', | ||
name: 'ASC' | ||
} | ||
}], | ||
}); | ||
}, | ||
} | ||
}); | ||
} | ||
); | ||
|
||
// The controller uses *injection*. This default injects a few things: | ||
// $scope -- This is the set of variables shared between JS and HTML. | ||
// crmApi, crmStatus, crmUiHelp -- These are services provided by civicrm-core. | ||
angular.module('gocardless').controller('GocardlessGoCardlessSettings', function($scope, crmApi4, crmStatus, crmUiHelp, various) { | ||
// The ts() and hs() functions help load strings for this module. | ||
var ts = $scope.ts = CRM.ts('uk.artfulrobot.civicrm.gocardless'); | ||
var hs = $scope.hs = crmUiHelp({file: 'CRM/gocardless/GoCardlessSettings'}); // See: templates/CRM/gocardless/GoCardlessSettings.hlp | ||
// Local variable for this controller (needed when inside a callback fn where `this` is not available). | ||
var ctrl = this; | ||
|
||
// Parse settings | ||
var gcSettings = {}; | ||
console.log("GOT ", various); | ||
if (various.gcSettings.value) { | ||
gcSettings = JSON.parse(various.gcSettings.value); | ||
if (!gcSettings) { | ||
gcSettings = {}; | ||
} | ||
} | ||
// Check settings have defaults. | ||
const defaults = { | ||
forceRecurring: false | ||
}; | ||
Object.keys(defaults).forEach(k => { | ||
if (!(k in gcSettings)) { | ||
gcSettings[k] = defaults[k]; | ||
} | ||
}); | ||
$scope.gcSettings = gcSettings; | ||
|
||
// Make pay processors accessible | ||
var ppTable = []; | ||
var ppNames = {}; | ||
var urlStub = window.location.href.replace(/^(https?:\/\/[^/]+).*$/, '$1'); | ||
various.paymentProcessors.forEach(pp => { | ||
var k; | ||
if (!(pp.name in ppNames)) { | ||
ppNames[pp.name] = { name: pp.name, p: pp}; | ||
} | ||
if (pp.is_test) { | ||
k = 'urlTest'; | ||
} | ||
else { | ||
k = 'urlLive'; | ||
} | ||
|
||
// Make URL. | ||
ppNames[pp.name][k] = urlStub + CRM.url('civicrm/payment/ipn/' + pp.id, null, 'front'); | ||
}); | ||
$scope.ppTable = Object.values(ppNames); | ||
|
||
this.save = function() { | ||
return crmStatus( | ||
// Status messages. For defaults, just use "{}" | ||
{start: ts('Saving...'), success: ts('Saved')}, | ||
// The save action. Note that crmApi() returns a promise. | ||
crmApi4('Setting', 'set', { values: { gocardless: JSON.stringify($scope.gcSettings)} }) | ||
); | ||
}; | ||
}); | ||
|
||
})(angular, CRM.$, CRM._); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.