Skip to content

Commit

Permalink
CRM-19213 another instance of mis-set payment_instrument_id
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 16, 2016
1 parent 204efed commit 16f3bd0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
6 changes: 1 addition & 5 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1244,11 +1244,7 @@ protected function processCreditCard($submittedValues, $lineItem, $contactID) {
'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)),
'thankyou_date' => CRM_Utils_Array::value('thankyou_date', $this->_params),
);

if (empty($paymentParams['is_pay_later'])) {
// @todo look up payment_instrument_id on payment processor table.
$contributionParams['payment_instrument_id'] = 1;
}
$contributionParams['payment_instrument_id'] = $this->_paymentProcessor['payment_instrument_id'];

$contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this,
$this->_params,
Expand Down
7 changes: 5 additions & 2 deletions api/v3/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ function civicrm_api3_generic_getfields($apiRequest, $unique = TRUE) {
$metadata = array();
}

// Normalize this for the sake of spec funcions
$apiRequest['params']['options']['get_options'] = $optionsToResolve;
// Hack for product api to pass tests.
if (!is_string($apiRequest['params']['options'])) {
// Normalize this for the sake of spec funcions
$apiRequest['params']['options']['get_options'] = $optionsToResolve;
}

// find any supplemental information
$hypApiRequest = array('entity' => $apiRequest['entity'], 'action' => $action, 'version' => $apiRequest['version']);
Expand Down
13 changes: 7 additions & 6 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,17 @@ public function testSubmitCreditCard() {
* Test the submit function on the contribution page.
*/
public function testSubmitCreditCardPayPal() {
$this->markTestIncomplete('Paypal is creating a complete contribution but we are testing pending
we are unsure at this point if this is correct behaviour or not');
return;
$form = new CRM_Contribute_Form_Contribution();
$paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0));
$form->_mode = 'Live';
$error = FALSE;
try {
$form->testSubmit(array(
'total_amount' => 50,
'financial_type_id' => 1,
'receive_date' => '04/21/2015',
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
Expand Down Expand Up @@ -229,12 +226,16 @@ public function testSubmitCreditCardPayPal() {
), CRM_Core_Action::ADD);
}
catch (Civi\Payment\Exception\PaymentProcessorException $e) {
$this->assertEquals('Transaction cannot be processed. Please use a different payment card.',
$e->getMessage());
$error = TRUE;
}
$this->assertTrue($error);
$this->callAPISuccessGetCount('Contribution', array(
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Pending',
'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
'return' => 'payment_instrument_id',
'id' => $paymentProcessorID,
)),
), 1);
$contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId));
$this->assertTrue(empty($contact['source']));
Expand Down
32 changes: 23 additions & 9 deletions tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ public function testSubmit() {
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
), 1);
$this->_checkFinancialRecords(array('id' => $contribution['id'], 'total_amount' => 50, 'financial_account_id' => 2), 'online');
$this->_checkFinancialRecords(array(
'id' => $contribution['id'],
'total_amount' => 50,
'financial_account_id' => 2,
'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
)),
), 'online');
}

/**
Expand Down Expand Up @@ -264,16 +272,20 @@ public function testSubmitRecur() {
$this->assertNotEmpty($contributionRecur['invoice_id']);
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id',
'Pending'), $contributionRecur['contribution_status_id']);
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id',
'Credit Card'), $contributionRecur['payment_instrument_id']);
$this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', array(
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
)), $contributionRecur['payment_instrument_id']);

$contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
'contact_id' => $this->_individualId,
'is_test' => TRUE,
));

$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id',
'Credit Card'), $contribution['payment_instrument_id']);
$this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', array(
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
)), $contribution['payment_instrument_id']);
$this->assertEquals($contributionRecur['id'], $contribution['contribution_recur_id']);

$this->callAPISuccessGetCount('LineItem', array(
Expand Down Expand Up @@ -328,15 +340,17 @@ public function testSubmitRecurCompleteInstant() {
'In Progress'), $contributionRecur['contribution_status_id']);
$this->assertNotEmpty($contributionRecur['next_sched_contribution_date']);
*/
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id',
'Credit Card'), $contributionRecur['payment_instrument_id']);
$paymentInstrumentID = $this->callAPISuccessGetValue('PaymentProcessor', array(
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
));
$this->assertEquals($paymentInstrumentID, $contributionRecur['payment_instrument_id']);

$contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
'contact_id' => $this->_individualId,
'is_test' => TRUE,
));
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id',
'Credit Card'), $contribution['payment_instrument_id']);
$this->assertEquals($paymentInstrumentID, $contribution['payment_instrument_id']);

$this->assertEquals('kettles boil water', $contribution['trxn_id']);
$this->assertEquals(.29, $contribution['fee_amount']);
Expand Down
10 changes: 9 additions & 1 deletion tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,15 @@ public function testSubmit() {
'contribution_id' => $contribution['id'],
), 1);

$this->_checkFinancialRecords(array('id' => $contribution['id'], 'total_amount' => 50, 'financial_account_id' => 2), 'online');
$this->_checkFinancialRecords(array(
'id' => $contribution['id'],
'total_amount' => 50,
'financial_account_id' => 2,
'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
)),
), 'online');
$this->mut->checkMailLog(array(
'50',
'Receipt text',
Expand Down
6 changes: 5 additions & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ public function testCreateContributionOnline() {
'total_amount' => 100.00,
'financial_type_id' => 1,
'contribution_page_id' => $contributionPage['id'],
'payment_processor' => 1,
'payment_processor' => $this->paymentProcessorID,
'trxn_id' => 12345,
'invoice_id' => 67890,
'source' => 'SSF',
Expand All @@ -860,6 +860,10 @@ public function testCreateContributionOnline() {
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
$contribution['payment_instrument_id'] = $this->callAPISuccessGetValue('PaymentProcessor', array(
'id' => $this->paymentProcessorID,
'return' => 'payment_instrument_id',
));
$this->_checkFinancialRecords($contribution, 'online');
}

Expand Down

0 comments on commit 16f3bd0

Please sign in to comment.