-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
[ready for core review] CRM-19153 Fixed future payment dates for future start pledge dates #8785
Changes from all commits
33dd32c
12e5325
d9a9ea3
27da207
603577b
31fdc70
3549232
cdc7779
a7c78cb
7e3c24b
3044f49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,7 +518,7 @@ public function postProcess() { | |
'calendar_month' => 'pledge_calendar_month', | ||
); | ||
if ($params['pledge_default_toggle'] == 'contribution_date') { | ||
$fieldValue = json_encode(array('contribution_date' => date('Ymd'))); | ||
$fieldValue = json_encode(array('contribution_date' => date('m/d/Y'))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This smells a bit to me since there are settings for how dates are formatted. Just because the default format is American m/d/Y doesn't mean this will work in Canada for Ymd or d/m/Y formats. I'm going to see about creating an instance to check this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this change was made in order to match how CiviCRM saves dates when used from the datepicker. I will check with Pradeep to see if there are any CRM functions I should be using instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JoeMurray |
||
} | ||
else { | ||
foreach ($pledgeDateFields as $key => $pledgeDateField) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1204,15 +1204,17 @@ public static function buildRecurParams($params) { | |
public static function getPledgeStartDate($date, $pledgeBlock) { | ||
$startDate = (array) json_decode($pledgeBlock['pledge_start_date']); | ||
list($field, $value) = each($startDate); | ||
if (!CRM_Utils_Array::value('is_pledge_start_date_visible', $pledgeBlock)) { | ||
return date('Ymd', strtotime($value)); | ||
} | ||
if (!CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) { | ||
if (!empty($date) && !CRM_Utils_Array::value('is_pledge_start_date_editable', $pledgeBlock)) { | ||
return $date; | ||
} | ||
if (empty($date)) { | ||
$date = $value; | ||
} | ||
switch ($field) { | ||
case 'contribution_date': | ||
$date = date('Ymd'); | ||
if (empty($date)) { | ||
$date = date('Ymd'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, how does this work with localization of date formats, and why Ymd here but m/d/Y above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same explanation as above. The only reason m/d/Y was used above was that CiviCRM was somehow messing up form submissions when Ymd was being used and storing the wrong date. |
||
} | ||
break; | ||
|
||
case 'calendar_date': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,8 +310,8 @@ public static function buildPledgeBlock($form) { | |
switch ($field) { | ||
case 'contribution_date': | ||
$form->addDate('start_date', ts('First installment payment')); | ||
$paymentDate = $value = date('d/m/Y'); | ||
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value); | ||
$paymentDate = $value = date('m/d/Y'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks problematic for same reasons as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also the value that will be saved into database. I have already taken CiviCRM's date formats into account in the next step. https://github.com/JMAConsulting/civicrm-core/blob/e9f772df5f18cc584a3db22b704419c280bf50ff/CRM/Pledge/BAO/PledgeBlock.php#L314 |
||
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(NULL); | ||
$form->assign('is_date', TRUE); | ||
break; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1003,4 +1003,53 @@ public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() { | |
$this->assertEquals($recur['contribution_status_id'], 5); // In progress status. | ||
} | ||
|
||
/** | ||
* Test submit pledge payment. | ||
* | ||
* - test submitting a pledge payment using contribution form. | ||
*/ | ||
public function testSubmitPledgePayment() { | ||
$this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment(); | ||
$pledge = $this->callAPISuccess('pledge', 'getsingle', array()); | ||
$params = array( | ||
'pledge_id' => $pledge['id'], | ||
); | ||
$submitParams = array( | ||
'id' => (int) $pledge['pledge_contribution_page_id'], | ||
'pledge_amount' => array(2 => 1), | ||
'billing_first_name' => 'Billy', | ||
'billing_middle_name' => 'Goat', | ||
'billing_last_name' => 'Gruff', | ||
'email' => '[email protected]', | ||
'payment_processor_id' => 1, | ||
'credit_card_number' => '4111111111111111', | ||
'credit_card_type' => 'Visa', | ||
'credit_card_exp_date' => array('M' => 9, 'Y' => 2040), | ||
'cvv2' => 123, | ||
'pledge_id' => $pledge['id'], | ||
'cid' => $pledge['contact_id'], | ||
'contact_id' => $pledge['contact_id'], | ||
'amount' => 100.00, | ||
'is_pledge' => TRUE, | ||
'pledge_block_id' => $this->_ids['pledge_block_id'], | ||
); | ||
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); | ||
$this->assertEquals($pledgePayment['values'][2]['status_id'], 2); | ||
|
||
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL); | ||
|
||
// Check if contribution created. | ||
$contribution = $this->callAPISuccess('contribution', 'getsingle', array( | ||
'contribution_page_id' => $pledge['pledge_contribution_page_id'], | ||
'contribution_status_id' => 'Completed', | ||
'contact_id' => $pledge['contact_id'], | ||
'contribution_recur_id' => array('IS NULL' => 1), | ||
)); | ||
|
||
$this->assertEquals(100.00, $contribution['total_amount']); | ||
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params); | ||
$this->assertEquals($pledgePayment['values'][2]['status_id'], 1, "This pledge payment should have been completed"); | ||
$this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlutfy @eileenmcnaughton I don't want to cause more work for JMA ;) but shouldn't date formats in reports be drawn from civicrm/admin/setting/date?action=reset=1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoeMurray I think the question is what is the destination once we have formatted the date, In this case here we are in the processFormContribution so most likely we are going to be inserting a date into the DB so need for format it into a date format that the db knows and i think Ymd is common for that. If we are building a form or something public then yes we would need to consider localised date formats. At least that is my thinking but @mlutfy @eileenmcnaughton correct me if i am wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree @seamuslee001