protected function markCompleted($endStatus, ServiceResponse $serviceResponse, $gatewayMessage) { // Get partial payments $partials = $this->payment->getPartialPayments()->filter('Status', $this->pendingState); if ($partials->count() > 0) { $i = 0; $total = $this->payment->MoneyAmount; foreach ($partials as $payment) { // only the first, eg. most recent payment should be considered valid. All others should be set to void if ($i === 0) { $total = PaymentMath::add($total, $payment->MoneyAmount); $payment->Status = 'Created'; $payment->setAmount(PaymentMath::multiply($payment->MoneyAmount, '-1')); $payment->Status = 'Refunded'; } else { $payment->Status = 'Void'; } $payment->write(); $i++; } // Ugly hack to set the money amount $this->payment->Status = 'Created'; $this->payment->setAmount($total); // If not everything was refunded, the payment should still have the "Captured" status if ($total > 0) { $endStatus = 'Captured'; } } parent::markCompleted($endStatus, $serviceResponse, $gatewayMessage); if ($endStatus === 'Captured') { $this->createMessage('PartiallyRefundedResponse', $gatewayMessage); } else { $this->createMessage('RefundedResponse', $gatewayMessage); } Helper::safeExtend($this->payment, 'onRefunded', $serviceResponse); }
protected function markCompleted($endStatus, ServiceResponse $serviceResponse, $gatewayMessage) { // Get partial payments $partials = $this->payment->getPartialPayments()->filter('Status', $this->pendingState); if ($partials->count() > 0) { $i = 0; $total = $originalTotal = $this->payment->MoneyAmount; foreach ($partials as $payment) { // only the first, eg. most recent payment should be considered valid. All others should be set to void if ($i === 0) { $total = PaymentMath::add($total, $payment->MoneyAmount); // deal with partial capture if ($payment->MoneyAmount < 0) { $payment->Status = 'Created'; $payment->setAmount(PaymentMath::multiply($payment->MoneyAmount, '-1')); $payment->Status = 'Captured'; } else { // void excess amounts $payment->Status = 'Void'; } } else { $payment->Status = 'Void'; } $payment->write(); $i++; } // Ugly hack to set the money amount $this->payment->Status = 'Created'; $this->payment->setAmount($total); // If not everything was captured (partial), // the payment should be refunded or still Authorized (in case multiple captures are possible) if ($total > 0 && $total < $originalTotal) { $endStatus = GatewayInfo::captureMode($this->payment->Gateway) === GatewayInfo::MULTIPLE ? 'Authorized' : 'Refunded'; } } parent::markCompleted($endStatus, $serviceResponse, $gatewayMessage); if ($endStatus === 'Captured') { $this->createMessage('CapturedResponse', $gatewayMessage); } else { $this->createMessage('PartiallyCapturedResponse', $gatewayMessage); } Helper::safeExtend($this->payment, 'onCaptured', $serviceResponse); }
protected function markCompleted($endStatus, ServiceResponse $serviceResponse, $gatewayMessage) { parent::markCompleted($endStatus, $serviceResponse, $gatewayMessage); $this->createMessage('VoidedResponse', $gatewayMessage); Helper::safeExtend($this->payment, 'onVoid', $serviceResponse); }