Skip to content
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

Update Next Recurring Donation Installment Amount #7086

Closed
wants to merge 100 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
67cbf8a
Initial commit of Update Single RD Installment work
lparrott Aug 16, 2022
b9f784a
RD Single Installment: Updating next Opportunity to match Next Paymen…
lparrott Aug 17, 2022
f7184fa
Merge remote-tracking branch 'origin/feature/242' into feature/242__u…
lparrott Aug 17, 2022
99be419
Clearing the Next Payment Amount field on Schedule after a Payment is…
lparrott Aug 18, 2022
ac9bec9
Clear the Next Payment Amount on RD Schedules when creating a new Opp…
lparrott Aug 22, 2022
d89a008
Merge remote-tracking branch 'origin/feature/242' into feature/242__u…
lparrott Aug 22, 2022
81fe216
Adding methods to send Next Payment Amount to Elevate Schedule
lparrott Aug 23, 2022
1a88269
Merge remote-tracking branch 'origin/feature/242' into feature/242__u…
lparrott Aug 23, 2022
273649b
Merge fdd36c8c77925b9627a1176fbb00063748f44efd into feature/242__upda…
salesforce-org-metaci[bot] Aug 24, 2022
c946150
Fixing Next Payment Amount scenarios, sending and clearing the value …
lparrott Aug 24, 2022
aef81be
Merge branch 'feature/242__updateInstallment' of https://github.com/S…
lparrott Aug 24, 2022
b190f44
Merge ce70b3e4f166f7961ef52591033c24b098d07aab into feature/242__upda…
salesforce-org-metaci[bot] Aug 27, 2022
6a1e3ca
Update Single RD Installment: fixing unit tests
lparrott Aug 29, 2022
5cf4618
Merge remote-tracking branch 'origin/feature/242' into feature/242__u…
lparrott Aug 31, 2022
91f8f6c
Update Single RD Installment PR feedback
lparrott Aug 31, 2022
ebab0b9
RD Single Installment, fixing scenario where multiple schedules have …
lparrott Aug 31, 2022
e6c03f4
Initial commit of Update Single Installment UI
lparrott Sep 1, 2022
2a2653e
Merge 6901cfc6177e557cdae567d36362bc8c3d874a28 into feature/242__upda…
salesforce-org-metaci[bot] Sep 7, 2022
1ae2e17
Merge 6901cfc6177e557cdae567d36362bc8c3d874a28 into feature/242__upda…
salesforce-org-metaci[bot] Sep 7, 2022
781f51d
update clear next payment date logic
andrewyu-salesforce Sep 7, 2022
9a4c9cb
Merge branch 'feature/242__updateInstallment' of github.com:Salesforc…
andrewyu-salesforce Sep 7, 2022
900e3a1
Merge 4d2d36e23f29ee84d7c1dceda1bf42ec5946d464 into feature/242__upda…
salesforce-org-metaci[bot] Sep 8, 2022
0a19875
Merge 4d2d36e23f29ee84d7c1dceda1bf42ec5946d464 into feature/242__upda…
salesforce-org-metaci[bot] Sep 8, 2022
fa7a956
RD Update Installment UI fixes
lparrott Sep 8, 2022
a92ad26
Merge remote-tracking branch 'origin/feature/242__updateInstallment' …
lparrott Sep 8, 2022
9fddedc
Merge branch 'feature/242__updateInstallmentUI' of https://github.com…
lparrott Sep 8, 2022
11cffd9
WIP Fixing Elevate connected Update Single Installment
lparrott Sep 9, 2022
dcd6d4f
Merge 81383ac6f80e9a7ba068b81c60cfb1490ffb099e into feature/242__upda…
salesforce-org-metaci[bot] Sep 9, 2022
4ab76dd
Merge 81383ac6f80e9a7ba068b81c60cfb1490ffb099e into feature/242__upda…
salesforce-org-metaci[bot] Sep 9, 2022
0df8f99
Update Single Installment, add ability to revert change, cleanup API …
lparrott Sep 12, 2022
1f12b58
Merge e59d64afbd136531a6708812e9d504811d5e37f2 into feature/242__upda…
salesforce-org-metaci[bot] Sep 14, 2022
7a3f58c
Merge e59d64afbd136531a6708812e9d504811d5e37f2 into feature/242__upda…
salesforce-org-metaci[bot] Sep 14, 2022
69b22e4
Adding Update Single Installment Jest tests
lparrott Sep 14, 2022
aa42e3e
Merge branch 'feature/242__updateInstallmentUI' of https://github.com…
lparrott Sep 14, 2022
7e2de55
Merge remote-tracking branch 'origin/feature/242__updateInstallment' …
lparrott Sep 15, 2022
a4c4eca
Cleanup of Change Next Installment component and test
lparrott Sep 16, 2022
db123f7
Update Single Installment, change UI modal tags, fixing error case
lparrott Sep 19, 2022
4bd056b
Update Single Installment, cleanup logic
lparrott Sep 21, 2022
855cdb6
Update Single Installment, fix pause scenario where Amount was cleared
lparrott Sep 22, 2022
8ec539d
Merge 62c8fee84a899d754045c5ad6b21dfc78028c124 into feature/242__upda…
salesforce-org-metaci[bot] Sep 23, 2022
95f0d72
Merge 62c8fee84a899d754045c5ad6b21dfc78028c124 into feature/242__upda…
salesforce-org-metaci[bot] Sep 23, 2022
d4ba723
Merge 24f348a34d19d0f6a9e391897a1d7286f0ecbfcd into feature/242__upda…
salesforce-org-metaci[bot] Sep 23, 2022
00df1fa
Merge 24f348a34d19d0f6a9e391897a1d7286f0ecbfcd into feature/242__upda…
salesforce-org-metaci[bot] Sep 23, 2022
03bf679
Merge ce75bf6a04ddc42b37a2c97eec7d3d0788eea7c7 into feature/242__upda…
salesforce-org-metaci[bot] Sep 25, 2022
461aecc
Merge ce75bf6a04ddc42b37a2c97eec7d3d0788eea7c7 into feature/242__upda…
salesforce-org-metaci[bot] Sep 25, 2022
ee00ef3
Merge b253e2d130f716a8f34c5d267dacfb2d9474af5b into feature/242__upda…
salesforce-org-metaci[bot] Sep 26, 2022
cb220c2
Merge b253e2d130f716a8f34c5d267dacfb2d9474af5b into feature/242__upda…
salesforce-org-metaci[bot] Sep 26, 2022
e5be4e0
Style update to change next installment modal
lparrott Oct 4, 2022
23fa915
Merge branch 'feature/242__updateInstallment' into feature/242__updat…
lparrott Oct 5, 2022
c8cb5e6
Merge pull request #7099 from SalesforceFoundation/feature/242__updat…
lparrott Oct 5, 2022
588c4be
Merge aa975adf5e96c30a773376277dc45d75bc3fea86 into feature/242__upda…
salesforce-org-metaci[bot] Oct 6, 2022
378d2fe
Merge e6b757809e6bf368b5f3f89c723c768dff023530 into feature/242__upda…
salesforce-org-metaci[bot] Oct 6, 2022
018aeec
Merge 09938ed05f3a17902871731598cc37099c323712 into feature/242__upda…
salesforce-org-metaci[bot] Oct 6, 2022
ae66dab
Merge cf568fa6ba797e9b04f40d5c69dd16572f03f395 into feature/242__upda…
salesforce-org-metaci[bot] Oct 7, 2022
a6af2d4
Merge 9e35e3dab558979d899e8ca645b8de7d1201a105 into feature/242__upda…
salesforce-org-metaci[bot] Oct 7, 2022
159d079
Merge dbb327770329a84b2428289bd4fbd3f61c0475b3 into feature/242__upda…
salesforce-org-metaci[bot] Oct 12, 2022
a8b775c
Merge 8f23cdfcc782d2953bf7f03e02cf2e4c805b9d34 into feature/242__upda…
salesforce-org-metaci[bot] Oct 13, 2022
a92c38a
Merge 61ac9448ce0cf3315c3a7167a4445977e47f7a1c into feature/242__upda…
salesforce-org-metaci[bot] Oct 13, 2022
4af9d71
Merge c81870a45ce7aae82de5dd8a4886a2452d8c1ba3 into feature/242__upda…
salesforce-org-metaci[bot] Oct 13, 2022
6b04833
Merge d5402ee0b8203ba9e5eac65593c0ed00e019d55d into feature/242__upda…
salesforce-org-metaci[bot] Oct 14, 2022
214453b
Merge 8ec862759d714fed2ddb478e92f6a2455982361e into feature/242__upda…
salesforce-org-metaci[bot] Oct 19, 2022
601f2ea
Merge fd4b8018c1abd0eb24a83dcbb4302e9d15594d15 into feature/242__upda…
salesforce-org-metaci[bot] Oct 20, 2022
a024fdc
Merge 4dd77023a37bce76188444084b200900d6cfb033 into feature/242__upda…
salesforce-org-metaci[bot] Oct 20, 2022
3dd1c47
Merge 0083af065a32daa08a3d9028fa8baa6925628f5f into feature/242__upda…
salesforce-org-metaci[bot] Oct 24, 2022
0c154aa
Merge 0da4d3c9ce7addab16df9f098579f6211d0ddb83 into feature/242__upda…
salesforce-org-metaci[bot] Oct 25, 2022
a15a683
Merge 3fcf7c26c85876a53a5d55ef9cfe0bb1c092e12b into feature/242__upda…
salesforce-org-metaci[bot] Oct 26, 2022
90ba539
Merge 50360258764d0407afe4e6adb0998ccbf0007d35 into feature/242__upda…
salesforce-org-metaci[bot] Oct 27, 2022
c9c0356
Merge 9c1164025d2a8cad9ca2461d36cbeaf3899ff029 into feature/242__upda…
salesforce-org-metaci[bot] Oct 31, 2022
212d3c2
Merge 961706d9bb1ca8e95b0a4d949c33883a5082a7b0 into feature/242__upda…
salesforce-org-metaci[bot] Nov 4, 2022
4e030e8
Merge 975b008bb7e9cfcb47c8cfa37977a58a8d39975e into feature/242__upda…
salesforce-org-metaci[bot] Nov 5, 2022
681acac
Merge e93cd63a09453c61e4b552f3392b5a089b9160f3 into feature/242__upda…
salesforce-org-metaci[bot] Nov 7, 2022
1e15c76
Merge a6a27553ae64151613110c9cf2ba77bdadd15a3b into feature/242__upda…
salesforce-org-metaci[bot] Nov 7, 2022
3f4154b
Merge ace32aa0841f9e5b1add0932f30df04a5b5cf5b2 into feature/242__upda…
salesforce-org-metaci[bot] Nov 9, 2022
6dc0111
Merge d357dccf4c3d0bf4c91df54b4a0c285f06de962f into feature/242__upda…
salesforce-org-metaci[bot] Nov 9, 2022
19fd9b7
Merge 3127098cc298920422182577f4c5b49adacf1c77 into feature/242__upda…
salesforce-org-metaci[bot] Nov 10, 2022
afed30f
Merge 8632f2433d59c116479f676089918bef5531c216 into feature/242__upda…
salesforce-org-metaci[bot] Nov 14, 2022
11395f0
Merge 753f434d42b4e1673a7021cf65d1112630002b9c into feature/242__upda…
salesforce-org-metaci[bot] Nov 14, 2022
f99ae24
Merge 7e56d007db383dc996b433e069b597079cc33493 into feature/242__upda…
salesforce-org-metaci[bot] Nov 14, 2022
c425c60
Merge 15858f0577a47f80beeb86f34bcf3ec1eb07e5e9 into feature/242__upda…
salesforce-org-metaci[bot] Nov 15, 2022
6593aeb
Merge 974c86c425e3ea6e89fe7c4f59780a17a6378cd4 into feature/242__upda…
salesforce-org-metaci[bot] Nov 16, 2022
4176d8f
Merge a35f1fd1e924a03db1368cd87651572a0607a8c2 into feature/242__upda…
salesforce-org-metaci[bot] Nov 17, 2022
f0a7832
Merge fdf146dd81cabd709fe2e6399ff56ee2457ec84f into feature/242__upda…
salesforce-org-metaci[bot] Nov 18, 2022
a42f6f5
Merge 08902d433c30d58dfd922571dff8df9998fb8b5e into feature/242__upda…
salesforce-org-metaci[bot] Nov 23, 2022
2a056b7
Merge f78f521bd4ff2740a1f85e795941fc14d94f45c2 into feature/242__upda…
salesforce-org-metaci[bot] Dec 14, 2022
96ddaa3
Merge e02dd7f4205d45b9dc43d2d7a5d2c3e78e6f5806 into feature/242__upda…
salesforce-org-metaci[bot] Feb 24, 2023
52ae757
Merge 87303b9a8582db095830e8c72882534cf070016b into feature/242__upda…
salesforce-org-metaci[bot] Mar 3, 2023
a0c3d92
Merge e656dc81c2d78c806ea633c83631fab967c4453f into feature/242__upda…
salesforce-org-metaci[bot] Mar 14, 2023
52e6454
Merge 1c4b65c7abdea74a8e4bf7cdfb098faa5a11c0c9 into feature/242__upda…
salesforce-org-metaci[bot] Jul 6, 2023
a816b40
Merge cded394e91fb157bebd9002be573eb7953de616e into feature/242__upda…
salesforce-org-metaci[bot] Jul 7, 2023
1a44e97
Merge c3e64a4dd196eb3d79bbda676b33806fd9dc40e2 into feature/242__upda…
salesforce-org-metaci[bot] Oct 10, 2023
be38407
Merge 653098fd0a8598d42eeb16851523c7e1da62197a into feature/242__upda…
salesforce-org-metaci[bot] Nov 28, 2023
40c5df8
Merge a3a82181410d402ff2df2a8d1907c8e4805bef5a into feature/242__upda…
salesforce-org-metaci[bot] Dec 13, 2023
33d0919
Merge f224cde65b98c3c516306b0a4b6954285cb0e7c0 into feature/242__upda…
salesforce-org-metaci[bot] Jan 17, 2024
30839c4
Merge 653258e6fd3cb662d12850d13ea44dc07a46c4be into feature/242__upda…
salesforce-org-metaci[bot] Feb 21, 2024
6c2f506
Merge c34c6c078e37b5e68bbd273aae9ee147651f57a0 into feature/242__upda…
salesforce-org-metaci[bot] Feb 26, 2024
1fd3f83
Merge a3e469be52070d9f8ae007c322084daa940a3e1d into feature/242__upda…
salesforce-org-metaci[bot] Apr 17, 2024
2727554
Merge 00585057ce2f9f96e55862562756c786205a2efa into feature/242__upda…
salesforce-org-metaci[bot] Jul 18, 2024
dfc1533
Merge 0f76cb38710bf436bb603cb7f19fa2083ac82b9d into feature/242__upda…
salesforce-org-metaci[bot] Jul 23, 2024
cb82943
Merge 2ca2abc03a232ecf0999c5ef4c052a481fc9a14b into feature/242__upda…
salesforce-org-metaci[bot] Jul 30, 2024
16a3f50
Merge d115ac240b7b1941b16e4b1fc7825705f0f0b3c7 into feature/242__upda…
salesforce-org-metaci[bot] Nov 28, 2024
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
30 changes: 29 additions & 1 deletion force-app/main/default/classes/PS_CommitmentRequest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ public inherited sharing class PS_CommitmentRequest {
: UserInfo.getDefaultCurrency();

if (isElevateScheduleFieldsChanged(rd, oldRd)) {
// If the schedule has a Next Payment Amount, we need to send it
Decimal nextPaymentAmount = scheduleService.getNextPaymentAmount(rd);
reqBody.deactivateOldSchedules();
setSchedules(reqBody, scheduleService.buildNewSchedules(rd), currencyCode);
setSchedules(reqBody, scheduleService.buildNewSchedules(rd, nextPaymentAmount), currencyCode);
}

if (isElevateCampaignChanged(rd, oldRd)) {
Expand All @@ -316,6 +318,26 @@ public inherited sharing class PS_CommitmentRequest {
return reqBody;
}

/***
* @description Constructs the edit commitment schedule request body for the specified Recurring Donation.
* @param rd Recurring Donation record
* @param nextPaymentAmount Next Payment Amount for Active Schedules
* @return RequestBody
*/
public RequestBody getUpdateScheduleRequestBody(npe03__Recurring_Donation__c rd, Decimal nextPaymentAmount) {
RequestBody reqBody = new RequestBody()
.withCommitmentId(rd.CommitmentId__c);

String currencyCode = UserInfo.isMultiCurrencyOrganization()
? (String) rd.get('CurrencyIsoCode')
: UserInfo.getDefaultCurrency();

reqBody.deactivateOldSchedules();
setSchedules(reqBody, scheduleService.buildNewSchedules(rd, nextPaymentAmount), currencyCode);

return reqBody;
}

private Map<String, Object> buildUpdatedProductMetadata(npe03__Recurring_Donation__c rd) {
Map<String, Object> existingProductMetadata = getExistingProductMetadata(rd.CommitmentId__c);
PS_ProductMetadata productMetadata = new PS_ProductMetadata()
Expand Down Expand Up @@ -743,6 +765,7 @@ public inherited sharing class PS_CommitmentRequest {
*/
public class Schedule {
public Integer amount;
public Integer nextPaymentAmount;
public String frequency;
public Integer frequencyInterval;
public String firstOccurrenceOnTimestamp;
Expand All @@ -767,6 +790,11 @@ public inherited sharing class PS_CommitmentRequest {
Double amount = rdSchedule.InstallmentAmount__c * currencyMultiplier;
this.amount = amount == null ? null : Integer.valueOf(amount);

Double nextPaymentAmount = rdSchedule.NextPaymentAmount__c;
this.nextPaymentAmount = nextPaymentAmount == null
? null
: Integer.valueOf(nextPaymentAmount * currencyMultiplier);

this.frequency = frequencyByInstallmentPeriod.get(rdSchedule.InstallmentPeriod__c);
this.frequencyInterval = rdSchedule.InstallmentFrequency__c == null
? null
Expand Down
44 changes: 44 additions & 0 deletions force-app/main/default/classes/PS_CommitmentRequest_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,50 @@ private with sharing class PS_CommitmentRequest_TEST {
System.assertEquals(FIRST_PAYMENT_DATE.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\''), schedule.firstOccurrenceOnTimestamp, 'First Payment Date should match');
}

/**
* @description Verifies that the update next payment amount request body is built based on the Recurring Donation and Schedule fields
*/
@isTest
private static void shouldBuildUpdateNextPaymentAmountRequestBody() {
RD2_ScheduleService.currentDate = CURRENT_DATE;
PS_IntegrationService.setConfiguration(PS_IntegrationServiceConfig_TEST.testConfig);
RD2_EnablementService_TEST.setRecurringDonations2Enabled();

Contact contact = getContact();
npe03__Recurring_Donation__c rd = getRecurringDonationBuilder()
.withContact(contact.Id)
.withInstallmentFrequency(INSTALLMENT_FREQUENCY)
.withCommitmentId(COMMITMENT_ID)
.withPaymentMethod(RD2_Constants.PAYMENT_PICKLIST_VALUE_CARD)
.build();

insert rd;

npe03__Recurring_Donation__c oldRd = rd.clone();

PS_CommitmentRequest request = new PS_CommitmentRequest();

Decimal nextPaymentAmount = 10.11;

Test.startTest();
PS_CommitmentRequest.RequestBody requestBody = request.getUpdateScheduleRequestBody(rd, nextPaymentAmount);
Test.stopTest();

System.assertEquals(UserInfo.getDefaultCurrency(), requestBody.currencyCode, 'Currency Code should match');
System.assertEquals(rd.CommitmentId__c, requestBody.id, 'Commitment Id should match');
System.assertEquals(true, requestBody.deactivateAllExistingSchedules, 'Deactivate Existing Schedules Boolean should set to true');
System.assertEquals(1, requestBody.schedules.size(),
'One schedule should be passed to the API: ' + requestBody.schedules);

PS_CommitmentRequest.Schedule schedule = requestBody.schedules[0];
System.assertEquals(AMOUNT * USD_CURRENCY_MULTIPLIER, schedule.amount, 'Recurring Amount should match');
System.assertEquals(nextPaymentAmount * USD_CURRENCY_MULTIPLIER, schedule.nextPaymentAmount, 'Next Payment Amount should match');
System.assertEquals('MONTH', schedule.frequency, 'Donation should be made monthly');
System.assertEquals('CREATE', schedule.operation, 'Schedule should be Created, not Updated');
System.assertEquals(INSTALLMENT_FREQUENCY, schedule.frequencyInterval, 'Donation frequency should match');
System.assertEquals(FIRST_PAYMENT_DATE.formatGMT('yyyy-MM-dd\'T\'HH:mm:ss\'Z\''), schedule.firstOccurrenceOnTimestamp, 'First Payment Date should match');
}

/**
* @description Verify update request when changing payment method to ACH
*/
Expand Down
25 changes: 25 additions & 0 deletions force-app/main/default/classes/RD2_CommitmentService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ public without sharing class RD2_CommitmentService {
}


/**
* @description Handles validation and Elevate recurring commitment creation
* @param rd Recurring Donation
* @param nextPaymentAmount The Next Payment Amount to set on the Schedule
* @return UTIL_Http.Response Payments API response
*/
public UTIL_Http.Response handleCommitmentNextPaymentAmount(npe03__Recurring_Donation__c rd, Decimal nextPaymentAmount) {
UTIL_Http.Response response;

// If we want to revert the Next Payment Amount in Elevate, we need to overwrite the value
if (nextPaymentAmount == null) {
nextPaymentAmount = rd.npe03__Amount__c;
}

PS_CommitmentRequest.RequestBody requestBody =
new PS_CommitmentRequest().getUpdateScheduleRequestBody(rd, nextPaymentAmount);

response = sendRequest(rd?.CommitmentId__c, JSON.serialize(requestBody),
PS_Request.ElevateEndpoint.COMMITMENT);

processResponse(rd, response);

return response;
}

/**
* @description Constructs Recurring Donation record from received fields specified in the JSON string,
* updates defaults that are otherwise updated in the trigger context, and
Expand Down
48 changes: 47 additions & 1 deletion force-app/main/default/classes/RD2_EntryFormController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,53 @@ public with sharing class RD2_EntryFormController {
return null;
}

/**
* @description Handles validation and Elevate recurring commitment creation
* @param rd Recurring Donation
* @param nextPaymentAmount The Next Payment Amount to set on the Schedule
* @return String Commitment API response
*/
@AuraEnabled
public static String handleNextPaymentAmount(Id rdId, Decimal nextPaymentAmount) {
try {
npe03__Recurring_Donation__c rd = selector.getRecurringDonationForUI(rdId);
UTIL_Http.Response response;

if (rd?.CommitmentId__c != null) {
response = commitmentService.handleCommitmentNextPaymentAmount(rd, nextPaymentAmount);

if (commitmentService.isCommitmentSuccess(response)) {
updateSchedulesWithNextPaymentAmount(rd, nextPaymentAmount);
}

return JSON.serialize(response);

} else {
updateSchedulesWithNextPaymentAmount(rd, nextPaymentAmount);
RD2_QueueableService.enqueueOppEvalService(rd.Id, true);
}
} catch (Exception ex) {
UTIL_AuraEnabledCommon.throwAuraHandledException(ex.getMessage());
}

return null;
}

/**
* @description Helper method to Update Schedule records with a new Next Payment Amount
* @param rd Recurring Donation
* @param nextPaymentAmount The Next Payment Amount to set on the Schedule
*/
private static void updateSchedulesWithNextPaymentAmount(npe03__Recurring_Donation__c rd,
Decimal nextPaymentAmount) {
List<npe03__Recurring_Donation__c> rdList = new List<npe03__Recurring_Donation__c>{rd};
RD2_ScheduleService scheduleService = new RD2_ScheduleService();
List<RecurringDonationSchedule__c> revisedSchedules =
scheduleService.setSchedulesWithNextPaymentAmount(rdList, nextPaymentAmount);

UTIL_DMLService.updateRecords(revisedSchedules);
}

/***
* @description Logs an error when a Recurring Donation cannot be created/updated
* @param recordId A Recurring Donation, or a donor (Contact/Account) Id
Expand All @@ -335,5 +382,4 @@ public with sharing class RD2_EntryFormController {
}



}
74 changes: 74 additions & 0 deletions force-app/main/default/classes/RD2_EntryFormController_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private with sharing class RD2_EntryFormController_TEST {
private static final String CARD_EXPIRATION_YEAR = '2019';
private static final String EVENT_VERSION = '1';
private static final String NO_CREATE_PERMISSION = 'NoCreate';
private static final Decimal NEXT_PAYMENT_AMOUNT = 10.11;

private static final TEST_SObjectGateway.RecurringDonationGateway rdGateway = new TEST_SObjectGateway.RecurringDonationGateway();
private static final TEST_SObjectGateway.ErrorGateway errorGateway = new TEST_SObjectGateway.ErrorGateway();
Expand Down Expand Up @@ -852,6 +853,79 @@ private with sharing class RD2_EntryFormController_TEST {
System.assertEquals(Label.RD2_AmountMustBeValid, result.errors[0].message, 'Wrong error message');
}

/***
* @description Verifies Recurring Donation should be validate and handle any error before calling Elevate API
*/
@IsTest
private static void shouldReturnSuccessWhenUpdatingRdNextPaymentAmount() {
RD2_EnablementService_TEST.setRecurringDonations2Enabled();
PS_IntegrationService.setConfiguration(PS_IntegrationServiceConfig_TEST.testConfig);

npe03__Recurring_Donation__c rd = rdGateway.getRecords()[0];

rd.CommitmentId__c = COMMITMENT_ID;
update rd;

Test.startTest();

UTIL_Http_TEST.mockRecordUpdateCalloutResponse(mockSuccessResponseBody());
String response = RD2_EntryFormController.handleNextPaymentAmount(rd.Id, NEXT_PAYMENT_AMOUNT);
Test.stopTest();

Integer statusCode;
String status;
JSONParser parser = JSON.createParser(response);

while (parser.nextToken() != null) {
if(parser.getCurrentToken() == JSONToken.FIELD_NAME) {
if (parser.getText() == 'statusCode') {
parser.nextToken();
statusCode = parser.getIntegerValue();

} else if (parser.getText() == 'status') {
parser.nextToken();
status = parser.getText();
}
}
}

System.assertNotEquals(null, response, 'Expected to receive a response from handleNextPaymentAmount');
System.assertEquals(UTIL_Http.STATUS_CODE_OK, statusCode,
'The response status code should match: ' + statusCode);
System.assertEquals(UTIL_Http.STATUS_OK, status,
'The response status should match: ' + status);
}

/***
* @description Verifies Recurring Donation should be validate and handle any error before calling Elevate API
*/
@IsTest
private static void shouldUpdateScheduleWhenUpdatingRdNextPaymentAmount() {
RD2_QueryService queryService = new RD2_QueryService();
RD2_EnablementService_TEST.setRecurringDonations2Enabled();
PS_IntegrationService.setConfiguration(PS_IntegrationServiceConfig_TEST.testConfig);

npe03__Recurring_Donation__c rd = rdGateway.getRecords()[0];

Test.startTest();

String response = RD2_EntryFormController.handleNextPaymentAmount(rd.Id, NEXT_PAYMENT_AMOUNT);

Test.stopTest();

System.assertEquals(null, response, 'Expected to receive a null response');

List<npe03__Recurring_Donation__c> rds =
queryService.getRecurringDonationsWithRelatedRecords(new Set<Id>{ rd.Id }, START_DATE);

rd = rds[0];
System.assertEquals(1, rd.RecurringDonationSchedules__r.size(), 'There should be 1 schedule');
System.assertEquals(true, rd.RecurringDonationSchedules__r[0].Active__c,
'The schedule should be Active');
System.assertEquals(NEXT_PAYMENT_AMOUNT, rd.RecurringDonationSchedules__r[0].NextPaymentAmount__c,
'The Next Payment Amount should be set');
}

// Helpers
////////////////

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ public inherited sharing class RD2_OpportunityEvaluationService {
}
}
// TODO Handle Past Due Installment

}

toggleTriggerState(false);
Expand Down Expand Up @@ -487,6 +488,7 @@ public inherited sharing class RD2_OpportunityEvaluationService {
//in order to calculate the Current/Next Year Values
rds = null;

List<npe03__Recurring_Donation__c> checkNextPaymentScheduleRds = new List<npe03__Recurring_Donation__c>();
List<npe03__Recurring_Donation__c> outdatedRDs = new List<npe03__Recurring_Donation__c>();
for (RD2_RecurringDonation rdRecord : rdRecords) {
//revise the Year Values only since other other values such as
Expand All @@ -499,10 +501,16 @@ public inherited sharing class RD2_OpportunityEvaluationService {
) {
outdatedRDs.add(rdRecord.getUpdate());
}

if (rdRecord.needsNextPaymentScheduleCheck()) {
checkNextPaymentScheduleRds.add(rdRecord.getSObject());
}
}

dbService.updateRecords(outdatedRDs);

dbService.updateRecords(scheduleService.getSchedulesWithClearedNextPaymentAmount(checkNextPaymentScheduleRds));

return this;
}

Expand Down
9 changes: 7 additions & 2 deletions force-app/main/default/classes/RD2_OpportunityService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,15 @@ public with sharing class RD2_OpportunityService {
return false;
}

Decimal installmentAmount = installment.installmentAmount;
if (installment.nextPaymentAmount != null) {
installmentAmount = installment.nextPaymentAmount;
}

Boolean isChanged = false;

if (opp.Amount != installment.installmentAmount) {
opp.Amount = installment.installmentAmount;
if (opp.Amount != installmentAmount) {
opp.Amount = installmentAmount;
isChanged = true;
}

Expand Down
Loading
Loading