Skip to content

Commit b708481

Browse files
committed
Added amount to partial capture and partial refund payment logs
1 parent d784d3b commit b708481

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

modules/log/commerce_log.commerce_log_templates.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ payment_authorized_captured:
4343
payment_partially_captured:
4444
category: commerce_payment
4545
label: 'Payment partially captured'
46-
template: '<p>Payment <em>{{ payment_remote_id }}</em> was partially captured.</p>'
46+
template: '<p>Payment <em>{{ payment_remote_id }}</em> was partially captured ({{ captured_amount }}).</p>'
4747
payment_captured:
4848
category: commerce_payment
4949
label: 'Payment captured'
5050
template: '<p>Payment <em>{{ payment_remote_id }}</em> was fully captured.</p>'
5151
payment_partially_refunded:
5252
category: commerce_payment
5353
label: 'Payment partially refunded'
54-
template: '<p>Payment <em>{{ payment_remote_id }}</em> was partially refunded.</p>'
54+
template: '<p>Payment <em>{{ payment_remote_id }}</em> was partially refunded ({{ refunded_amount }}).</p>'
5555
payment_refunded:
5656
category: commerce_payment
5757
label: 'Payment refunded'

modules/log/src/EventSubscriber/PaymentEventSubscriber.php

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function onPartialCapture(PaymentEvent $event) {
167167
$payment = $event->getPayment();
168168
$this->logStorage->generate($payment, 'payment_partially_captured', [
169169
'payment_remote_id' => $payment->getRemoteId(),
170+
'captured_amount' => $event->getAmount(),
170171
])->save();
171172
}
172173

@@ -193,6 +194,7 @@ public function onPartialRefund(PaymentEvent $event) {
193194
$payment = $event->getPayment();
194195
$this->logStorage->generate($payment, 'payment_partially_refunded', [
195196
'payment_remote_id' => $payment->getRemoteId(),
197+
'refunded_amount' => $event->getAmount(),
196198
])->save();
197199
}
198200

modules/payment/src/Event/PaymentEvent.php

+26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\commerce_payment\Event;
44

55
use Drupal\commerce_payment\Entity\PaymentInterface;
6+
use Drupal\commerce_price\Price;
67
use Symfony\Component\EventDispatcher\Event;
78

89
/**
@@ -19,6 +20,13 @@ class PaymentEvent extends Event {
1920
*/
2021
protected $payment;
2122

23+
/**
24+
* The payment operation amount.
25+
*
26+
* @var \Drupal\commerce_price\Price
27+
*/
28+
protected $amount;
29+
2230
/**
2331
* Constructs a new PaymentEvent.
2432
*
@@ -29,6 +37,24 @@ public function __construct(PaymentInterface $payment) {
2937
$this->payment = $payment;
3038
}
3139

40+
/**
41+
* @param \Drupal\commerce_price\Price $amount
42+
* The payment operation amount.
43+
*/
44+
public function setAmount(Price $amount) {
45+
$this->amount = $amount;
46+
}
47+
48+
/**
49+
* Gets the payment operation amount.
50+
*
51+
* @return \Drupal\commerce_price\Price
52+
* The payment operation amount.
53+
*/
54+
public function getAmount() {
55+
return $this->amount;
56+
}
57+
3258
/**
3359
* Gets the payment.
3460
*

modules/payment/src/PluginForm/PaymentCaptureForm.php

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
4141

4242
/** @var \Drupal\commerce_payment\Event\PaymentEvent $event */
4343
$event = new PaymentEvent($payment);
44+
$event->setAmount($amount);
4445
/** @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $event_dispatcher */
4546
$event_dispatcher = \Drupal::service('event_dispatcher');
4647
$event_name = ($payment->getOrder()->getTotalPrice()->greaterThan($payment->getAmount())) ? PaymentEvents::PAYMENT_PARTIALLY_CAPTURED : PaymentEvents::PAYMENT_CAPTURED;

modules/payment/src/PluginForm/PaymentRefundForm.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
5555

5656
/** @var \Drupal\commerce_payment\Event\PaymentEvent $event */
5757
$event = new PaymentEvent($payment);
58+
$event->setAmount($amount);
5859
/** @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $event_dispatcher */
5960
$event_dispatcher = \Drupal::service('event_dispatcher');
6061
$event_name = ($payment->getBalance()->isZero()) ? PaymentEvents::PAYMENT_REFUNDED : PaymentEvents::PAYMENT_PARTIALLY_REFUNDED;

0 commit comments

Comments
 (0)