}
}
+ /**
+ * Update Credit Card Details in civicrm_financial_trxn table.
+ *
+ * @param int $contributionID
+ * @param int $panTruncation
+ * @param int $cardType
+ *
+ */
+ public static function updateCreditCardDetails($contributionID, $panTruncation, $cardType) {
+ $financialTrxn = civicrm_api3('EntityFinancialTrxn', 'get', array(
+ 'return' => array('financial_trxn_id.payment_processor_id', 'financial_trxn_id'),
+ 'entity_table' => 'civicrm_contribution',
+ 'entity_id' => $contributionID,
+ 'financial_trxn_id.is_payment' => TRUE,
+ 'options' => array('sort' => 'financial_trxn_id DESC', 'limit' => 1),
+ ));
+
+ if (!$financialTrxn['count']) {
+ return NULL;
+ }
+
+ $financialTrxn = $financialTrxn['values'][$financialTrxn['id']];
+ $paymentProcessorID = CRM_Utils_Array::value('financial_trxn_id.payment_processor_id', $financialTrxn);
+
+ if ($paymentProcessorID) {
+ return NULL;
+ }
+
+ $financialTrxnId = $financialTrxn['financial_trxn_id'];
+ $trxnparams = array('id' => $financialTrxnId);
+ if (isset($cardType)) {
+ $trxnparams['card_type'] = $cardType;
+ }
+ if (isset($panTruncation)) {
+ $trxnparams['pan_truncation'] = $panTruncation;
+ }
+ civicrm_api3('FinancialTrxn', 'create', $trxnparams);
+ }
+
}
$this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime("+1 month")));
}
+ /**
+ * Test for updateCreditCardDetails().
+ */
+ public function testUpdateCreditCardDetailsUsingContributionAPI() {
+ $cid = $this->individualCreate();
+ $params = array(
+ 'contact_id' => $cid,
+ 'receive_date' => '2016-01-20',
+ 'total_amount' => 100,
+ 'financial_type_id' => 1,
+ );
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
+ $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'DESC');
+ $financialTrxn = $this->callAPISuccessGetSingle(
+ 'FinancialTrxn',
+ array(
+ 'id' => $lastFinancialTrxnId['financialTrxnId'],
+ 'return' => array('card_type', 'pan_truncation'),
+ )
+ );
+ $this->assertEquals(CRM_Utils_Array::value('card_type', $financialTrxn), NULL);
+ $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
+ $params = array(
+ 'card_type' => 2,
+ 'pan_truncation' => 4567,
+ 'id' => $contribution->id,
+ );
+ $this->callAPISuccess("Contribution", "create", $params);
+ $financialTrxn = $this->callAPISuccessGetSingle(
+ 'FinancialTrxn',
+ array(
+ 'id' => $lastFinancialTrxnId['financialTrxnId'],
+ 'return' => array('card_type', 'pan_truncation'),
+ )
+ );
+ $this->assertEquals($financialTrxn['card_type'], 2);
+ $this->assertEquals($financialTrxn['pan_truncation'], 4567);
+ }
+
+ /**
+ * Test for updateCreditCardDetails().
+ */
+ public function testUpdateCreditCardDetails() {
+ $cid = $this->individualCreate();
+ $params = array(
+ 'contact_id' => $cid,
+ 'receive_date' => '2016-01-20',
+ 'total_amount' => 100,
+ 'financial_type_id' => 1,
+ );
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
+ $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'DESC');
+ $financialTrxn = $this->callAPISuccessGetSingle(
+ 'FinancialTrxn',
+ array(
+ 'id' => $lastFinancialTrxnId['financialTrxnId'],
+ 'return' => array('card_type', 'pan_truncation'),
+ )
+ );
+ $this->assertEquals(CRM_Utils_Array::value('card_type', $financialTrxn), NULL);
+ $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
+ CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($contribution->id, 4567, 2);
+ $financialTrxn = $this->callAPISuccessGetSingle(
+ 'FinancialTrxn',
+ array(
+ 'id' => $lastFinancialTrxnId['financialTrxnId'],
+ 'return' => array('card_type', 'pan_truncation'),
+ )
+ );
+ $this->assertEquals($financialTrxn['card_type'], 2);
+ $this->assertEquals($financialTrxn['pan_truncation'], 4567);
+ }
+
}