Exemplo n.º 1
0
 /**
  *
  *
  * @update 1.1.1
  * */
 function do_checkout($order_id)
 {
     update_post_meta($order_id, 'status', 'pending');
     $order_token = get_post_meta($order_id, 'order_token_code', true);
     //Destroy cart on success
     STCart::destroy_cart();
     $booking_success = STCart::get_success_link();
     do_action('st_email_after_booking', $order_id);
     do_action('st_booking_submit_form_success', $order_id);
     if ($order_token) {
         $array = array('order_token_code' => $order_token);
     } else {
         $array = array('order_code' => $order_id);
     }
     return array('status' => true, 'redirect' => add_query_arg($array, $booking_success));
 }
Exemplo n.º 2
0
 function check_completePurchase($order_id = false)
 {
     //Check cart is not empty
     if ($order_id and false !== get_post_status($order_id)) {
         $total = get_post_meta($order_id, 'total_price', true);
         $gateway = Omnipay::create('PayPal_Express');
         $gateway->setUsername($this->apiUserName);
         $gateway->setPassword($this->apiPass);
         $gateway->setSignature($this->apiSignature);
         $gateway->setTestMode(true);
         $amount = TravelHelper::convert_money($total);
         $order_token_code = get_post_meta($order_id, 'order_token_code', true);
         if (!$order_token_code) {
             $array = array('gateway_name' => 'st_paypal', 'order_code' => $order_id, 'status' => 'success');
             $array_error = array('gateway_name' => 'st_paypal', 'order_code' => $order_id, 'status' => 'error');
         } else {
             $array = array('gateway_name' => 'st_paypal', 'order_token_code' => $order_token_code, 'status' => 'success');
             $array_error = array('gateway_name' => 'st_paypal', 'order_token_code' => $order_token_code, 'status' => 'error');
         }
         $response = $gateway->completePurchase(array('amount' => (double) $amount, 'currency' => TravelHelper::get_current_currency('name'), 'description' => __('Traveler Booking', ST_TEXTDOMAIN), 'returnUrl' => add_query_arg($array, STCart::get_success_link()), 'cancelUrl' => add_query_arg($array_error, STCart::get_success_link())))->send();
         if ($response->isSuccessful()) {
             $data = $response->getData();
             $data2 = $gateway->fetchCheckout(array('transactionReference' => $data['TOKEN']))->send();
             $transaction_data = $data2->getData();
             //Try to create user and create new orders with paypal transaction detail
             return STGatewayPaypal::paypal_checkout($transaction_data, $order_id);
             //return true;
         } elseif ($response->isRedirect()) {
             //$response->redirect(); // this will automatically forward the customer
             return array('status' => false, 'redirect_url' => $response->getRedirectUrl(), 'func' => 'check_completePurchase');
             //                    return ;
         } else {
             // not successful
             return array('status' => false, 'message' => $response->getMessage());
         }
     } else {
         // not successful
         return array('status' => false, 'message' => __('Order Code is not exists', ST_TEXTDOMAIN));
     }
 }