Skip to content
Snippets Groups Projects
Commit 321cfcb0 authored by Rich Lott / Artful Robot's avatar Rich Lott / Artful Robot
Browse files

Fix descriptions, change test mode.

parent fb9fa229
No related branches found
No related tags found
No related merge requests found
......@@ -130,9 +130,16 @@ class UpdateGiving extends InlayType {
// Load data as before, should work.
$loadedData = $this->loadAllData($requestBody);
if (!$loadedData || count($loadedData['crs']) !== 1) {
return [];
Civi::log()->warning("inlayupdategiving error/misuse (public error code IUG2): handleChangeRequest called but we don't have a single cr.", compact('requestBody', 'loadedData') + [
'inlay' => $this->getName(),
'testMode' => $this->config['testMode'],
]);
return ['error' => 'Sorry, something went wrong. Please let us know (code IUG2)'];
}
$cr = $loadedData['crs'][0];
if ($this->config['testMode'] && empty($cr['is_test'])) {
return ['error' => 'In test mode, refusing to update a real subscription!'];
}
// Validate input.
$newAmountPennies = Money::of($requestBody['newAmount'], $cr['currency'])->getMinorAmount()->toInt();
$oldAmountPennies = Money::of($cr['amount'], $cr['currency'])->getMinorAmount()->toInt();
......@@ -194,7 +201,7 @@ class UpdateGiving extends InlayType {
public function getGivingDetails(int $contactID): array {
$crs = ContributionRecur::get(FALSE)
->addWhere('contact_id', '=', $contactID)
->addWhere('is_test', '=', $this->config['testMode'])
->addWhere('is_test', 'IN', $this->config['testMode'] ? [0, 1] : [0])
->addWhere('contribution_status_id:name', '=', 'In Progress')
->addSelect('amount', 'currency',
'frequency_unit:label', /*month*/
......@@ -204,15 +211,16 @@ class UpdateGiving extends InlayType {
'payment_instrument_id:label',
'financial_type_id:name',
'financial_type_id:label',
'is_test',
)
->execute()->getArrayCopy();
foreach ($crs as &$cr) {
$cr['lastCn'] = Contribution::get(FALSE)
->addWhere('contribution_recur_id', '=', $cr['id'])
->addWhere('is_test', '=', $this->config['testMode'])
->addWhere('is_test', 'IN', $this->config['testMode'] ? [0, 1] : [0])
->addWhere('is_template', '=', FALSE)
->addSelect('total_amount', 'receive_date')
->addSelect('total_amount', 'receive_date', 'is_test')
->addOrderBy('receive_date', 'DESC')
->setLimit(1)->execute()->first();
}
......@@ -240,7 +248,7 @@ class UpdateGiving extends InlayType {
* Returns HTML summary of a recur, and last payment date if present.
*/
public function summariseCr(array $cr): string {
$description = '<strong>' . htmlspecialchars($this->summariseCrAmountAndInterval($cr)) . '</strong>';
$description = 'You are giving <strong>' . htmlspecialchars($this->summariseCrAmountAndInterval($cr)) . '</strong>';
if (!empty($cr['lastCn'])) {
$description .= ' Last payment on ' . date('j M Y', strtotime($cr['lastCn']['receive_date'])) . ', thank you.';
}
......
......@@ -53,6 +53,7 @@
confirmUserNot.addEventListener('click', e => {
e.preventDefault();
e.stopPropagation();
CiviCRMInlay.debug('User identified as not who we sent the link to...');
window.location.replace(inlay.initData.donatePageURL);
});
......@@ -88,7 +89,7 @@
+ '</li></ul><p>If you would like, you can consolidate these into a single payment instead.</p>';
}
else if (d.descriptions.length === 1) {
currentGivingNode.innerHTML = '<p>You are currently giving ' + d.descriptions[0] + '</p>';
currentGivingNode.innerHTML = '<p>' + d.descriptions[0] + '</p>';
}
else {
// hmmm.
......@@ -138,7 +139,7 @@
},
});
if (!result.success) {
alert("Sorry, something we weren’t able to make the change. Please get in touch.");
alert("Sorry, something we weren’t able to make the change. " + (result.error || ''));
return;
}
CiviCRMInlay.debug({ result });
......@@ -149,6 +150,7 @@
}
else {
// We're unable to make a simple change, send them to the form.
CiviCRMInlay.debug('Sending user to new donation form as not simple.');
window.location.replace(inlay.initData.donatePageURL);
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment