$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'];
$paymentTrxnParams = array_intersect_key($params, array_fill_keys($whiteList, 1));
$paymentTrxnParams['is_payment'] = 1;
- if (!empty($params['payment_processor'])) {
- // I can't find evidence this is passed in - I was gonna just remove it but decided to deprecate as I see getToFinancialAccount
- // also anticipates it.
- CRM_Core_Error::deprecatedFunctionWarning('passing payment_processor is deprecated - use payment_processor_id');
- $paymentTrxnParams['payment_processor_id'] = $params['payment_processor'];
- }
+
if (isset($paymentTrxnParams['payment_processor_id']) && empty($paymentTrxnParams['payment_processor_id'])) {
// Don't pass 0 - ie the Pay Later processor as it is a pseudo-processor.
unset($paymentTrxnParams['payment_processor_id']);
return [];
}
+ /**
+ * Get options for a given contribution field.
+ *
+ * @param string $fieldName
+ * @param string $context see CRM_Core_DAO::buildOptionsContext.
+ * @param array $props whatever is known about this dao object.
+ *
+ * @return array|bool
+ * @see CRM_Core_DAO::buildOptions
+ *
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = []) {
+ $params = [];
+ if ($fieldName === 'financial_account_id') {
+ // Pseudo-field - let's help out.
+ return CRM_Core_BAO_FinancialTrxn::buildOptions('to_financial_account_id', $context, $props);
+ }
+ return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+ }
+
/**
* Retrieve DB object based on input parameters.
*
/**
* Test create payment api for pay later contribution with partial payment.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreatePaymentPayLaterPartialPayment() {
$this->createLoggedInUser();
'contribution_status_id' => 2,
'is_pay_later' => 1,
];
- $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
+ $contribution = $this->callAPISuccess('Order', 'create', $contributionParams);
//Create partial payment
$params = [
'contribution_id' => $contribution['id'],
$this->callAPISuccessGetCount('Activity', ['target_contact_id' => $this->_individualId, 'activity_type_id' => 'Payment'], 2);
}
+ /**
+ * Test that Payment.create uses the to_account of the payment processor.
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
+ */
+ public function testPaymentWithProcessorWithOddFinancialAccount() {
+ $processor = $this->dummyProcessorCreate(['financial_account_id' => 'Deposit Bank Account', 'payment_instrument_id' => 'Cash']);
+ $processor2 = $this->dummyProcessorCreate(['financial_account_id' => 'Payment Processor Account', 'name' => 'p2', 'payment_instrument_id' => 'EFT']);
+ $contributionParams = [
+ 'total_amount' => 100,
+ 'currency' => 'USD',
+ 'contact_id' => $this->_individualId,
+ 'financial_type_id' => 1,
+ 'contribution_status_id' => 'Pending',
+ ];
+ $order = $this->callAPISuccess('Order', 'create', $contributionParams);
+ $this->callAPISuccess('Payment', 'create', ['payment_processor_id' => $processor->getID(), 'total_amount' => 6, 'contribution_id' => $order['id']]);
+ $this->callAPISuccess('Payment', 'create', ['payment_processor_id' => $processor2->getID(), 'total_amount' => 15, 'contribution_id' => $order['id']]);
+ $payments = $this->callAPISuccess('Payment', 'get', ['sequential' => 1, 'contribution_id' => $order['id']])['values'];
+ $this->assertEquals('Deposit Bank Account', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'to_financial_account_id', $payments[0]['to_financial_account_id']));
+ $this->assertEquals('Payment Processor Account', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'to_financial_account_id', $payments[1]['to_financial_account_id']));
+ $this->assertEquals('Accounts Receivable', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'from_financial_account_id', $payments[0]['from_financial_account_id']));
+ $this->assertEquals('Accounts Receivable', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'from_financial_account_id', $payments[1]['from_financial_account_id']));
+ $this->assertEquals('Cash', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $payments[0]['payment_instrument_id']));
+ $this->assertEquals('EFT', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $payments[1]['payment_instrument_id']));
+ // $order = $this->callAPISuccessGetSingle('Order', ['id' => $processor->getID()]);
+ // $this->assertEquals('Cash', CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $order['payment_instrument_id']));
+ }
+
/**
* Add a location to our event.
*
* @param int $eventID
+ *
+ * @throws \CRM_Core_Exception
*/
protected function addLocationToEvent($eventID) {
$addressParams = [