Ejemplo n.º 1
0
 /**
  * Send an email with a copy of the order for payment
  *
  * Accessing the extension point is needed to dynamically set send_confirmation to true.
  * Normally, an unpaid order will not generate an email.
  * @see onPlaceOrder is an extension within the placeOrder function within the OrderProcessor class
  */
 public function onPlaceOrder()
 {
     $gateway = Checkout::get($this->owner)->getSelectedPaymentMethod();
     if (OrderProcessor::config()->bank_deposit_send_confirmation && GatewayInfo::isManual($gateway) && $this->owner->Status == "Unpaid") {
         OrderProcessor::config()->send_confirmation = true;
     } else {
         OrderProcessor::config()->send_confirmation = false;
     }
 }
Ejemplo n.º 2
0
 public function checkoutSubmit($data, $form)
 {
     // form validation has passed by this point, so we can save data
     $this->config->setData($form->getData());
     $order = $this->config->getOrder();
     $gateway = Checkout::get($order)->getSelectedPaymentMethod(false);
     if (GatewayInfo::isOffsite($gateway) || GatewayInfo::isManual($gateway) || $this->config->getComponentByType('OnsitePaymentCheckoutComponent')) {
         return $this->submitpayment($data, $form);
     }
     return $this->controller->redirect($this->controller->Link('payment'));
 }
Ejemplo n.º 3
0
 /**
  * Void/cancel a payment
  *
  * If the transaction-reference of the payment to capture is known, pass it via $data as
  * `transactionReference` parameter. Otherwise the service will try to look up the reference
  * from previous payment messages.
  *
  * If there's no transaction-reference to be found, this method will raise an exception.
  *
  * @inheritdoc
  * @throws MissingParameterException if no transaction reference can be found from messages or parameters
  */
 public function initiate($data = array())
 {
     if (!$this->payment->canVoid()) {
         throw new InvalidConfigurationException('Voiding of this payment not allowed.');
     }
     if (!$this->payment->isInDB()) {
         $this->payment->write();
     }
     $reference = null;
     // If the gateway isn't manual, we need a transaction reference to void a payment
     if (!GatewayInfo::isManual($this->payment->Gateway)) {
         if (!empty($data['transactionReference'])) {
             $reference = $data['transactionReference'];
         } elseif (!empty($data['receipt'])) {
             // legacy code?
             $reference = $data['receipt'];
         } else {
             $reference = $this->payment->TransactionReference;
         }
         if (empty($reference)) {
             throw new MissingParameterException('transactionReference not found and is not set as parameter');
         }
     }
     $gateway = $this->oGateway();
     if (!$gateway->supportsVoid()) {
         throw new InvalidConfigurationException(sprintf('The gateway "%s" doesn\'t support void', $this->payment->Gateway));
     }
     $gatewayData = array_merge($data, array('transactionReference' => $reference, 'notifyUrl' => $this->getEndpointUrl('notify')));
     $this->extend('onBeforeVoid', $gatewayData);
     $request = $this->oGateway()->void($gatewayData);
     $this->extend('onAfterVoid', $request);
     $message = $this->createMessage($this->requestMessageType, $request);
     $message->write();
     try {
         $response = $this->response = $request->send();
     } catch (OmnipayException $e) {
         $this->createMessage($this->errorMessageType, $e);
         return $this->generateServiceResponse(ServiceResponse::SERVICE_ERROR);
     }
     Helper::safeExtend($this, 'onAfterSendVoid', $request, $response);
     $serviceResponse = $this->wrapOmnipayResponse($response);
     if ($serviceResponse->isAwaitingNotification()) {
         $this->payment->Status = $this->pendingState;
         $this->payment->write();
     } else {
         if ($serviceResponse->isError()) {
             $this->createMessage($this->errorMessageType, $response);
         } else {
             $this->markCompleted($this->endState, $serviceResponse, $response);
         }
     }
     return $serviceResponse;
 }
Ejemplo n.º 4
0
 /**
  * Get the total captured or authorized amount, excluding Manual payments.
  * @return float
  */
 public function TotalPaidOrAuthorized()
 {
     $paid = 0;
     if ($payments = $this->owner->Payments()) {
         foreach ($payments as $payment) {
             // Captured and authorized payments (which aren't manual) should count towards the total
             if ($payment->Status == 'Captured' || $payment->Status == 'Authorized' && !GatewayInfo::isManual($payment->Gateway)) {
                 $paid += $payment->Amount;
             }
         }
     }
     return $paid;
 }
 /**
  * Capture a previously authorized payment
  *
  * If the transaction-reference of the payment to capture is known, pass it via $data as
  * `transactionReference` parameter. Otherwise the service will try to look up the reference
  * from previous payment messages.
  *
  * If there's no transaction-reference to be found, this method will raise an exception.
  *
  * You can issue partial captures (if the gateway supports it) by passing an `amount` parameter in the $data
  * array. The amount can also exceed the authorized amount, if the configuration allows it (`max_capture` setting).
  * An amount that exceeds the authorized amount will always be considered as a full capture!
  * If the amount given is not a number, or if it exceeds the total possible capture amount, an exception
  * will be raised.
  *
  * @inheritdoc
  * @throws MissingParameterException if no transaction reference can be found from messages or parameters
  * @throws InvalidParameterException if the amount parameter was invalid
  */
 public function initiate($data = array())
 {
     if (!$this->payment->canCapture()) {
         throw new InvalidConfigurationException('Capture of this payment not allowed.');
     }
     if (!$this->payment->isInDB()) {
         $this->payment->write();
     }
     $reference = null;
     // If the gateway isn't manual, we need a transaction reference to refund a payment
     if (!GatewayInfo::isManual($this->payment->Gateway)) {
         if (!empty($data['transactionReference'])) {
             $reference = $data['transactionReference'];
         } elseif (!empty($data['receipt'])) {
             // legacy code?
             $reference = $data['receipt'];
         } else {
             $reference = $this->payment->TransactionReference;
         }
         if (empty($reference)) {
             throw new MissingParameterException('transactionReference not found and is not set as parameter');
         }
     }
     $gateway = $this->oGateway();
     if (!$gateway->supportsCapture()) {
         throw new InvalidConfigurationException(sprintf('The gateway "%s" doesn\'t support capture', $this->payment->Gateway));
     }
     $authorized = $amount = $this->payment->MoneyAmount;
     $diff = 0;
     if (!empty($data['amount'])) {
         $amount = $data['amount'];
         if (!is_numeric($amount)) {
             throw new InvalidParameterException('The "amount" parameter has to be numeric.');
         }
         if (!($amount > 0)) {
             throw new InvalidParameterException('The "amount" parameter has to be positive.');
         }
         // check if the amount exceeds the max. amount that can be captured
         if (PaymentMath::compare($this->payment->getMaxCaptureAmount(), $amount) === -1) {
             throw new InvalidParameterException('The "amount" given exceeds the amount that can be captured.');
         }
         $diff = PaymentMath::subtract($amount, $authorized);
     }
     if ($diff < 0 && !$this->payment->canCapture(null, true)) {
         throw new InvalidParameterException('This payment cannot be partially captured (unsupported by gateway).');
     }
     $gatewayData = array_merge($data, array('amount' => (double) $amount, 'currency' => $this->payment->MoneyCurrency, 'transactionReference' => $reference, 'notifyUrl' => $this->getEndpointUrl('notify')));
     $this->extend('onBeforeCapture', $gatewayData);
     $request = $this->oGateway()->capture($gatewayData);
     $this->extend('onAfterCapture', $request);
     $message = $this->createMessage($this->requestMessageType, $request);
     $message->write();
     try {
         $response = $this->response = $request->send();
     } catch (OmnipayException $e) {
         $this->createMessage($this->errorMessageType, $e);
         return $this->generateServiceResponse(ServiceResponse::SERVICE_ERROR);
     }
     Helper::safeExtend($this, 'onAfterSendCapture', $request, $response);
     $serviceResponse = $this->wrapOmnipayResponse($response);
     if ($serviceResponse->isAwaitingNotification()) {
         if ($diff < 0) {
             $this->createPartialPayment(PaymentMath::multiply($amount, '-1'), $this->pendingState);
         } elseif ($diff > 0) {
             $this->createPartialPayment($diff, $this->pendingState);
         }
         $this->payment->Status = $this->pendingState;
         $this->payment->write();
     } else {
         if ($serviceResponse->isError()) {
             $this->createMessage($this->errorMessageType, $response);
         } else {
             if ($diff < 0) {
                 $this->createPartialPayment(PaymentMath::multiply($amount, '-1'), $this->pendingState);
             } elseif ($diff > 0) {
                 $this->createPartialPayment($diff, $this->pendingState);
             }
             $this->markCompleted($this->endState, $serviceResponse, $response);
         }
     }
     return $serviceResponse;
 }
 public function php($data)
 {
     // Check if we should do a payment
     if (Form::current_action() == 'dopayment' && !empty($data['PaymentMethod'])) {
         $gateway = $data['PaymentMethod'];
         // If the gateway isn't manual and not offsite, Check for credit-card fields!
         if (!GatewayInfo::isManual($gateway) && !GatewayInfo::isOffsite($gateway)) {
             // Merge the required fields and the Credit-Card fields that are required for the gateway
             $this->required = array_merge($this->required, array_intersect(array('type', 'name', 'number', 'startMonth', 'startYear', 'expiryMonth', 'expiryYear', 'cvv', 'issueNumber'), GatewayInfo::requiredFields($gateway)));
         }
     }
     return parent::php($data);
 }