When interacting with Salesforce programmatically through Apex code you can initialize recurring payment collection via RaiseNow based on existing NPC & NPSP Recurring Donations in Salesforce. This is especially useful in the case of migrations or regular imports of recurring donations from sources outside Salesforce wich are partially or fully automated.
For this purpose RaiseNow provides the public method:
RaiseNow.BulkImportBatchController.addRecurringDonations();
The following snippet illustrates the use of this method:
// ExampleImport.cls
// ...
// First, create a RaiseNow__Bulk_Import__c object which holds as the wrapper
// to your import. You can specify two parameters:
// - the name of the record
// - the type of the import. There is currently only one option: "create-and-link-rnw-record".
// In return, you'll get the Id of the created RaiseNow__Bulk_Import__c record.
Id raiseNowBulkImportRecordId = RaiseNow.BulkImportBatchController.createBulkImport(
'My Bulk Import Name',
'create-and-link-rnw-record'
);
// Next, gather some NPSP Recurring Donations which should be imported.
// This is usually the place where you'd apply your custom logic on
// how to retrieve adequate records to import to RaiseNow.
List<npe03__Recurring_Donation__c> recList = [SELECT Id FROM npe03__Recurring_Donation__c LIMIT 20];
// For each NPSP Recurring Donation you'd like to import, RaiseNow needs some
// particular information:
// - the NPSP Recurring Donation Id
// - the BIC (Business Identifier Code, ISO 9362) to identify the bank. E.g. for PostFinance this is "POFICHBEXXX".
// - the Banking Clearing Number to identify the bank. E.g. for PostFinance this is "09000"
// - the Payment Method to use for charging the Recurring Donation. Is one of:
// - "Direct Debit CH-DD"
// - "Direct Debit CH-TA"
// - "Swiss Payment Slip with Reference Number"
// - the hard copy record identifier to identify the hard copy contract.
Map<Id, RaiseNow.BulkImportBatchController.BulkImportRecord> records = new Map<Id, RaiseNow.BulkImportBatchController.BulkImportRecord>();
for (npe03__Recurring_Donation__c recurringDonation : recList) {
RaiseNow.BulkImportBatchController.BulkImportRecord record = new RaiseNow.BulkImportBatchController.BulkImportRecord();
// In your real code this would have to set correct values for each recurring donation
record.bic = 'POFICHBEXXX';
record.iban = 'CH3908704016075473007';
record.clearing = '09000';
record.paymentMethod = 'Direct Debit CH-DD';
record.hardCopyRecordIdentifier = 'Some Identifier';
records.put(recurringDonation.Id, record);
}
// Now is the time to trigger the import to RaiseNow.
// Invoking this method will perform the following actions:
// - create a CSV file with the given recurring donations
// - attaches the CSV file to the RaiseNow__Bulk_Import__c record with the given Id
// - triggers a callout to RaiseNow to import the data from the CSV file. This is done
// in a separate job which Id is attached to the RaiseNow__Bulk_Import__c record.
// In return you'll get the Id of the batchJob, by which you can monitor the
// status of the import and check whether CSV file generation has completed successfully.
Id batchJobId = RaiseNow.BulkImportBatchController.addRecurringDonations(
raiseNowBulkImportRecordId,
records,
200 // batchSize - this should not exceed 200
);
// Verify status:
AsyncApexJob jobInfo = [SELECT Status, NumberOfErrors FROM AsyncApexJob WHERE Id = :batchJobId];
// ...
// Once you've verified the successful run of the batch job, you
// can also assert the success of the callout to RaiseNow.
Id calloutJobId = RaiseNow.BulkImportBatchController.getUploadJobId(
raiseNowBulkImportRecordId
);
// Verify status:
AsyncApexJob jobInfo = [SELECT Status, NumberOfErrors FROM AsyncApexJob WHERE Id = :calloutJobId];
// ...
// ...
Supported values for paymentMethod are
- Direct Debit CH-DD
- Direct Debit CH-TA
- Swiss Payment Slip with Reference Number
Comments
0 comments
Please sign in to leave a comment.