コード例 #1
0
 protected function markCompleted($endStatus, ServiceResponse $serviceResponse, $gatewayMessage)
 {
     parent::markCompleted($endStatus, $serviceResponse, $gatewayMessage);
     $this->createMessage('AuthorizedResponse', $gatewayMessage);
     Helper::safeExtend($this->payment, 'onAuthorized', $serviceResponse);
 }
コード例 #2
0
 /**
  * Generate a service response
  * @param int $flags a combination of service flags
  * @param AbstractResponse|NotificationInterface|null $omnipayData the response or notification from the Omnipay gateway
  * @return ServiceResponse
  */
 protected function generateServiceResponse($flags, $omnipayData = null)
 {
     $response = new ServiceResponse($this->payment, $flags);
     if ($omnipayData) {
         $response->setOmnipayResponse($omnipayData);
     }
     // redirects and notifications don't need a target URL.
     if (!$response->isNotification() && !$response->isRedirect()) {
         $response->setTargetUrl($response->isError() || $response->isCancelled() ? $this->payment->FailureUrl : $this->payment->SuccessUrl);
     }
     // Hook to update service response via extensions. This can be used to customize the service response
     Helper::safeExtend($this, 'updateServiceResponse', $response);
     return $response;
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }