public function __construct($controller, $name, Order $order)
 {
     $this->order = $order;
     $fields = FieldList::create(HiddenField::create('OrderID', '', $order->ID));
     $actions = FieldList::create();
     //payment
     if (self::config()->allow_paying && $order->canPay()) {
         $gateways = GatewayInfo::get_supported_gateways();
         //remove manual gateways
         foreach ($gateways as $gateway => $gatewayname) {
             if (GatewayInfo::is_manual($gateway)) {
                 unset($gateways[$gateway]);
             }
         }
         if (!empty($gateways)) {
             $fields->push(HeaderField::create("MakePaymentHeader", _t("OrderActionsForm.MAKEPAYMENT", "Make Payment")));
             $outstandingfield = Currency::create();
             $outstandingfield->setValue($order->TotalOutstanding());
             $fields->push(LiteralField::create("Outstanding", sprintf(_t("OrderActionsForm.OUTSTANDING", "Outstanding: %s"), $outstandingfield->Nice())));
             $fields->push(OptionsetField::create('PaymentMethod', _t("OrderActionsForm.PAYMENTMETHOD", "Payment Method"), $gateways, key($gateways)));
             $actions->push(FormAction::create('dopayment', _t('OrderActionsForm.PAYORDER', 'Pay outstanding balance')));
         }
     }
     //cancelling
     if (self::config()->allow_cancelling && $order->canCancel()) {
         $actions->push(FormAction::create('docancel', _t('OrderActionsForm.CANCELORDER', 'Cancel this order')));
     }
     parent::__construct($controller, $name, $fields, $actions);
     $this->extend("updateForm", $order);
 }
 /**
  * Create a new payment for an order
  */
 public function createPayment($gateway)
 {
     if (!GatewayInfo::isSupported($gateway)) {
         $this->error(_t("PaymentProcessor.InvalidGateway", "`{gateway}` isn't a valid payment gateway.", 'gateway is the name of the payment gateway', array('gateway' => $gateway)));
         return false;
     }
     if (!$this->order->canPay(Member::currentUser())) {
         $this->error(_t("PaymentProcessor.CantPay", "Order can't be paid for."));
         return false;
     }
     $payment = Payment::create()->init($gateway, $this->order->TotalOutstanding(true), ShopConfig::get_base_currency());
     $this->order->Payments()->add($payment);
     return $payment;
 }
 /**
  * Create a new payment for an order
  */
 public function createPayment($gateway)
 {
     if (!GatewayInfo::is_supported($gateway)) {
         $this->error(_t("PaymentProcessor.INVALIDGATEWAY", "`{$gateway}` isn't a valid payment gateway."));
         return false;
     }
     if (!$this->order->canPay(Member::currentUser())) {
         $this->error(_t("PaymentProcessor.CANTPAY", "Order can't be paid for."));
         return false;
     }
     $payment = Payment::create()->init($gateway, $this->order->TotalOutstanding(), ShopConfig::get_base_currency());
     $this->order->Payments()->add($payment);
     return $payment;
 }
 /**
  * @return Form (OrderForm_Payment) | Array
  **/
 function PaymentForm()
 {
     if ($this->currentOrder) {
         if ($this->currentOrder->canPay()) {
             Requirements::javascript("ecommerce/javascript/EcomPayment.js");
             return OrderForm_Payment::create($this, 'PaymentForm', $this->currentOrder, $this->Link("thankyou"));
         } else {
             $this->errorMessage = _t("EcommercePaymentController.CANNOTMAKEPAYMENT", "You can not make a payment for this order.");
         }
     } else {
         $this->errorMessage = _t("EcommercePaymentController.ORDERCANNOTBEFOUND", "Order can not be found.");
     }
     return array();
 }
 public function __construct($controller, $name, Order $order)
 {
     $this->order = $order;
     $fields = FieldList::create(HiddenField::create('OrderID', '', $order->ID));
     $actions = FieldList::create();
     //payment
     if (self::config()->allow_paying && $order->canPay()) {
         $gateways = GatewayInfo::getSupportedGateways();
         //remove manual gateways
         foreach ($gateways as $gateway => $gatewayname) {
             if (GatewayInfo::isManual($gateway)) {
                 unset($gateways[$gateway]);
             }
         }
         if (!empty($gateways)) {
             $fields->push(HeaderField::create("MakePaymentHeader", _t("OrderActionsForm.MakePayment", "Make Payment")));
             $outstandingfield = Currency::create();
             $outstandingfield->setValue($order->TotalOutstanding(true));
             $fields->push(LiteralField::create("Outstanding", _t('Order.OutstandingWithAmount', 'Outstanding: {Amount}', '', array('Amount' => $outstandingfield->Nice()))));
             $fields->push(OptionsetField::create('PaymentMethod', _t("OrderActionsForm.PaymentMethod", "Payment Method"), $gateways, key($gateways)));
             if ($ccFields = $this->getCCFields($gateways)) {
                 if ($this->config()->include_jquery) {
                     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.min.js');
                 }
                 Requirements::javascript(SHOP_DIR . '/javascript/OrderActionsForm.js');
                 $fields->push($ccFields);
             }
             $actions->push(FormAction::create('dopayment', _t('OrderActionsForm.PayOrder', 'Pay outstanding balance')));
         }
     }
     //cancelling
     if (self::config()->allow_cancelling && $order->canCancel()) {
         $actions->push(FormAction::create('docancel', _t('OrderActionsForm.CancelOrder', 'Cancel this order')));
     }
     parent::__construct($controller, $name, $fields, $actions, OrderActionsForm_Validator::create(array('PaymentMethod')));
     $this->extend("updateForm", $order);
 }