/**
  * Process the callback data from the payment provider
  */
 public function callback($request)
 {
     if (Director::isDev()) {
         $secret_key = StripePayment::config()->test_secret_key;
         $publish_key = StripePayment::config()->test_publish_key;
     } else {
         $secret_key = StripePayment::config()->live_secret_key;
         $publish_key = StripePayment::config()->live_publish_key;
     }
     Stripe::setApiKey($secret_key);
     $site = SiteConfig::current_site_config();
     $order = $this->getOrderData();
     $cart = ShoppingCart::get();
     $this->extend('onBeforeCallback');
     $error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error');
     $data = $this->request->postVars();
     $status = "error";
     // Get the credit card details submitted by the form
     $token = $data['stripeToken'];
     $order_no = Session::get("StripePayment.OrderNumber");
     $order = Estimate::get()->filter("OrderNumber", $order_no)->first();
     if ($order_no && $order) {
         // Create the charge on Stripe's servers - this will charge
         // the user's card
         try {
             $success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', $order_no);
             $charge = StripeCharge::create(array("amount" => round($order->Total->Value * 100), "currency" => strtolower(Checkout::config()->currency_code), "source" => $token, "metadata" => array("Order" => $order_no)));
             $order->convertToOrder();
             $order->write();
             $order = Order::get()->byID($order->ID);
             $order->Status = "paid";
             $order->PaymentProvider = "Stripe";
             $order->PaymentNo = $charge->id;
             $order->write();
             return $this->redirect($success_url);
         } catch (Exception $e) {
             $order->Status = "failed";
             $order->write();
             return $this->redirect($error_url);
         }
     } else {
         return $this->redirect($error_url);
     }
 }
예제 #2
0
function payment_buttons_js()
{
    if (osc_get_preference('paypal_enabled', 'payment') == 1) {
        ?>
        <div name="result_div" id="result_div"></div>
        <script type="text/javascript">
            var rd = document.getElementById("result_div");
        </script>
        <?php 
    }
    if (osc_get_preference('braintree_enabled', 'payment') == 1) {
        BraintreePayment::dialogJS();
    }
    if (osc_get_preference('stripe_enabled', 'payment') == 1) {
        StripePayment::dialogJS();
    }
    if (osc_get_preference('coinjar_enabled', 'payment') == 1) {
        CoinjarPayment::dialogJS();
    }
}