Пример #1
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $id_order = $this->request->param('id');
     //retrieve info for the item in DB
     $order = new Model_Order();
     $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         //its a fraud...lets let him know
         if ($order->is_fraud() === TRUE) {
             Alert::set(Alert::ERROR, __('We had, issues with your transaction. Please try paying with another paymethod.'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
         }
         //Functions from https://github.com/paymill/paybutton-examples
         $privateApiKey = Core::config('payment.paymill_private');
         if (isset($_POST['paymillToken'])) {
             $token = $_POST['paymillToken'];
             $client = Paymill::request('clients/', array(), $privateApiKey);
             $payment = Paymill::request('payments/', array('token' => $token, 'client' => $client['id']), $privateApiKey);
             $transaction = Paymill::request('transactions/', array('amount' => Paymill::money_format($order->amount), 'currency' => $order->currency, 'client' => $client['id'], 'payment' => $payment['id'], 'description' => $order->product->title), $privateApiKey);
             if (isset($transaction['status']) && $transaction['status'] == 'closed') {
                 //mark as paid
                 $order->confirm_payment('paymill', Core::post('paymillToken'), NULL, NULL, NULL, Paymill::calculate_fee($order->amount));
                 //redirect him to his ads
                 Alert::set(Alert::SUCCESS, __('Thanks for your payment!'));
                 $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'goal', 'id' => $order->id_order)));
             } else {
                 $msg = __('Transaction not successful!');
                 if (!$transaction['status'] == 'closed') {
                     $msg .= ' - ' . $transaction['data']['error'];
                 }
                 Kohana::$log->add(Log::ERROR, 'Paymill ' . $msg);
                 Alert::set(Alert::ERROR, $msg);
                 $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
             }
         } else {
             Alert::set(Alert::INFO, __('Please fill your card details.'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
     }
 }
Пример #2
0
        src="https://button.paymill.com/v1/"
        id="button"
        data-label="<?php 
echo __('Pay with Card');
?>
"
        data-title="<?php 
echo Model_Order::product_desc($order->id_product);
?>
"
        data-description="<?php 
echo Text::limit_chars(Text::removebbcode($order->description), 30, NULL, TRUE);
?>
"
        data-amount="<?php 
echo Paymill::money_format($order->amount);
?>
"
        data-currency="<?php 
echo $order->currency;
?>
"
        data-submit-button="<?php 
echo __('Pay');
?>
 <?php 
echo i18n::format_currency($order->amount, $order->currency);
?>
"
        data-elv="false"
        data-lang="en-GB"