Skip to content

Commit 342e95e

Browse files
Merge pull request #260 from jaapjansma/form_procesor_integration2
Form processor improvement
2 parents 29f9ad1 + 8f04ef6 commit 342e95e

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

Civi/OmnipayMultiProcessor/ActionProvider/DoOnlinePayment.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,34 @@ class DoOnlinePayment extends AbstractAction {
3232
* @throws \Exception
3333
*/
3434
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
35-
$paymentParams['contribution_id'] = $parameters->getParameter('contribution_id');
36-
$paymentParams['amount'] = (float) $parameters->getParameter('total_amount');
37-
$paymentParams['currency'] = $parameters->getParameter('currency');
35+
$paymentParams['contributionID'] = $parameters->getParameter('contribution_id');
3836
$paymentParams['description'] = $parameters->getParameter('description');
3937
$successUrl = $parameters->getParameter('success_url');
4038
$cancelurl = $parameters->getParameter('cancel_url');
4139

42-
$paymentProcessor = $this->getPaymentProcessorByName($this->configuration->getParameter('payment_processor'));
40+
$contribution = \Civi\Api4\Contribution::get(FALSE)
41+
->addWhere('id', '=', $parameters->getParameter('contribution_id'))
42+
->execute()
43+
->first();
44+
if (empty($contribution['trxn_id'])) {
45+
\Civi\Api4\Contribution::update(FALSE)
46+
->addValue('trxn_id', $parameters->getParameter('contribution_id'))
47+
->addWhere('id', '=', $parameters->getParameter('contribution_id'))
48+
->execute();
49+
}
50+
$paymentParams['amount'] = (float) $contribution['total_amount'];
51+
$paymentParams['currency'] = $contribution['currency'];
52+
53+
if ($parameters->doesParameterExists('payment_processor')) {
54+
$paymentProcessorId = $parameters->getParameter('payment_processor');
55+
} elseif ($this->configuration->doesParameterExists('payment_processor')) {
56+
$paymentProcessorId = $this->configuration->getParameter('payment_processor');
57+
}
58+
if (!$paymentProcessorId) {
59+
throw new ExecutionException('Invalid Payment Processor');
60+
}
61+
62+
$paymentProcessor = $this->getPaymentProcessorByName($paymentProcessorId);
4363
if (!$paymentProcessor) {
4464
throw new ExecutionException('Invalid Payment Processor');
4565
}
@@ -74,7 +94,7 @@ public function getConfigurationSpecification() {
7494
$paymentProcessorOptions[$paymentProcessor['name']] = $paymentProcessor['title'];
7595
}
7696
return new SpecificationBag(array(
77-
new Specification('payment_processor', 'String', E::ts('Payment Processor'), TRUE, null, null, $paymentProcessorOptions),
97+
new Specification('payment_processor', 'String', E::ts('Payment Processor'), FALSE, null, null, $paymentProcessorOptions),
7898
));
7999
}
80100

@@ -84,13 +104,16 @@ public function getConfigurationSpecification() {
84104
* @return SpecificationBag
85105
*/
86106
public function getParameterSpecification() {
107+
$paymentProcessorOptions = [];
108+
foreach($this->getPaymentProcessors() as $paymentProcessor) {
109+
$paymentProcessorOptions[$paymentProcessor['name']] = $paymentProcessor['title'];
110+
}
87111
return new SpecificationBag([
88112
new Specification('contribution_id', 'Integer', E::ts('Contribution ID'), TRUE),
89-
new Specification('total_amount', 'Float', E::ts('Amount'), TRUE),
90-
new OptionGroupSpecification('currency', 'currencies_enabled', E::ts('Currency'), TRUE),
91113
new Specification('success_url', 'String', E::ts('Success URL'), TRUE),
92114
new Specification('cancel_url', 'String', E::ts('Cancel URL'), TRUE),
93115
new Specification('description', 'String', E::ts('Payment Description'), TRUE),
116+
new Specification('payment_processor', 'String', E::ts('Payment Processor'), FALSE, null, null, $paymentProcessorOptions),
94117
]);
95118
}
96119

0 commit comments

Comments
 (0)