Skip to content

Commit

Permalink
Merge pull request #15687 from eileenmcnaughton/add_pay_date
Browse files Browse the repository at this point in the history
Cleanup date handling on Payment.create
  • Loading branch information
mattwire authored Nov 1, 2019
2 parents edcc7f1 + 4c68d68 commit 2543ccb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
12 changes: 0 additions & 12 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,6 @@ public function processCreditCard() {
$config->defaultCurrency
);

if (!empty($this->_params['trxn_date'])) {
$this->_params['receive_date'] = $this->_params['trxn_date'];
}

if (empty($this->_params['receive_date'])) {
$this->_params['receive_date'] = date('YmdHis');
}

if (empty($this->_params['invoice_id'])) {
$this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
}
Expand Down Expand Up @@ -469,10 +461,6 @@ public function processCreditCard() {
$this->_params = array_merge($this->_params, $result);
}

if (empty($this->_params['receive_date'])) {
$this->_params['receive_date'] = $now;
}

$this->set('params', $this->_params);

// set source if not set
Expand Down
3 changes: 1 addition & 2 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function create($params) {
$isPaymentCompletesContribution = self::isPaymentCompletesContribution($params['contribution_id'], $params['total_amount']);
$lineItems = self::getPayableLineItems($params);

$whiteList = ['check_number', 'payment_processor_id', 'fee_amount', 'total_amount', 'contribution_id', 'net_amount', 'card_type_id', 'pan_truncation', 'trxn_result_code', 'payment_instrument_id', 'trxn_id'];
$whiteList = ['check_number', 'payment_processor_id', 'fee_amount', 'total_amount', 'contribution_id', 'net_amount', 'card_type_id', 'pan_truncation', 'trxn_result_code', 'payment_instrument_id', 'trxn_id', 'trxn_date'];
$paymentTrxnParams = array_intersect_key($params, array_fill_keys($whiteList, 1));
$paymentTrxnParams['is_payment'] = 1;
if (!empty($params['payment_processor'])) {
Expand Down Expand Up @@ -89,7 +89,6 @@ public static function create($params) {
if ($params['total_amount'] > 0) {
$paymentTrxnParams['to_financial_account_id'] = CRM_Contribute_BAO_Contribution::getToFinancialAccount($contribution, $params);
$paymentTrxnParams['from_financial_account_id'] = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship($contribution['financial_type_id'], 'Accounts Receivable Account is');
$paymentTrxnParams['trxn_date'] = CRM_Utils_Array::value('trxn_date', $params, CRM_Utils_Array::value('contribution_receive_date', $params, date('YmdHis')));
$paymentTrxnParams['currency'] = $contribution['currency'];
$paymentTrxnParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'status_id', 'Completed');

Expand Down
16 changes: 11 additions & 5 deletions api/v3/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ function _civicrm_api3_payment_create_spec(&$params) {
'api.aliases' => ['payment_id'],
],
'trxn_date' => [
'title' => ts('Cancel Date'),
'title' => ts('Payment Date'),
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'api.default' => 'now',
'api.required' => TRUE,
],
'is_send_contribution_notification' => [
'title' => ts('Send out notifications based on contribution status change?'),
Expand Down Expand Up @@ -321,22 +323,26 @@ function _civicrm_api3_payment_create_spec(&$params) {
function _civicrm_api3_payment_get_spec(&$params) {
$params = [
'contribution_id' => [
'title' => 'Contribution ID',
'title' => ts('Contribution ID'),
'type' => CRM_Utils_Type::T_INT,
],
'entity_table' => [
'title' => 'Entity Table',
'title' => ts('Entity Table'),
'api.default' => 'civicrm_contribution',
],
'entity_id' => [
'title' => 'Entity ID',
'title' => ts('Entity ID'),
'type' => CRM_Utils_Type::T_INT,
'api.aliases' => ['contribution_id'],
],
'trxn_id' => [
'title' => 'Transaction ID',
'title' => ts('Transaction ID'),
'type' => CRM_Utils_Type::T_STRING,
],
'trxn_date' => [
'title' => ts('Payment Date'),
'type' => CRM_Utils_Type::T_TIMESTAMP,
],
];
}

Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ public function testAddPaymentForPendingPayLaterContribution() {
$this->submitPayment(70);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->assertEquals('2019-04-01 00:00:00', $contribution['receive_date']);
$payment = $this->callAPISuccessGetSingle('Payment', ['contribution_id' => $contribution['id']]);
$this->assertEquals('2017-04-11 13:05:11', $payment['trxn_date']);

// pay additional amount
$this->submitPayment(30);
Expand Down Expand Up @@ -430,8 +433,6 @@ public function submitPayment($amount, $mode = NULL, $isEmailReceipt = FALSE) {
'total_amount' => $amount,
'currency' => 'USD',
'financial_type_id' => 1,
'receive_date' => '04/21/2015',
'receive_date_time' => '11:27PM',
'trxn_date' => '2017-04-11 13:05:11',
'payment_processor_id' => 0,
'is_email_receipt' => $isEmailReceipt,
Expand Down Expand Up @@ -493,6 +494,7 @@ protected function createPendingOrder() {
$orderParams = array_merge($this->_params, [
'contribution_status_id' => 'Pending',
'is_pay_later' => 1,
'receive_date' => '2019-04-01',
]);
$contribution = $this->callAPISuccess('Order', 'create', $orderParams);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
Expand Down

0 comments on commit 2543ccb

Please sign in to comment.