Esempio n. 1
0
 /**
  * catch ajax et-setup-payment and process order generate json send back to clien
  * json data: array
  *             - 'success' => $nvp['ACK']
  *             - 'data' => array('data' , 'url'  => 'the payment gateway url')
  *             - 'paymentType' => $paymentType
  *
  * @package AE Payment
  * @category payment
  *
  * @since  1.0
  * @author  Dakachi
  */
 function setup_payment()
 {
     global $user_ID;
     $order_data = $this->setup_orderdata($_POST);
     $plans = $this->get_plans();
     if (empty($plans)) {
         wp_send_json(array('success' => false, 'msg' => __("There is no payment plan.", ET_DOMAIN)));
     }
     $adID = isset($_POST['ID']) ? $_POST['ID'] : '';
     $author = isset($_POST['author']) ? $_POST['author'] : $user_ID;
     $packageID = isset($_POST['packageID']) ? $_POST['packageID'] : '';
     $paymentType = isset($_POST['paymentType']) ? $_POST['paymentType'] : '';
     foreach ($plans as $key => $value) {
         if ($value->sku == $packageID) {
             $plan = $value;
             break;
         }
     }
     $plan->ID = $plan->sku;
     // if($adID) $plan->post_id = $adID;
     // $ship    =   array( 'street_address' => isset($company_location['full_location']) ? $company_location['full_location'] : __("No location", ET_DOMAIN));
     // filter shipping
     $ship = apply_filters('ae_payment_ship', array(), $order_data, $_POST);
     /**
      * filter order data
      *
      * @param Array $order_data
      * @param Array $_POST Client submitted data
      *
      * @since  1.0
      * @author  Dakachi
      */
     $order_data = apply_filters('ae_payment_order_data', $order_data, $_POST);
     // insert order into database
     $order = new AE_Order($order_data, $ship);
     $order->add_product((array) $plan);
     $order_data = $order->generate_data_to_pay();
     // write session
     et_write_session('order_id', $order_data['ID']);
     et_write_session('ad_id', $adID);
     $arg = apply_filters('ae_payment_links', array('return' => et_get_page_link('process-payment'), 'cancel' => et_get_page_link('process-payment')));
     /**
      * process payment
      */
     $paymentType_raw = $paymentType;
     $paymentType = strtoupper($paymentType);
     /**
      * factory create payment visitor
      */
     $visitor = AE_Payment_Factory::createPaymentVisitor($paymentType, $order, $paymentType_raw);
     // setup visitor setting
     $visitor->set_settings($arg);
     // accept visitor process payment
     $nvp = $order->accept($visitor);
     if ($nvp['ACK']) {
         $response = array('success' => $nvp['ACK'], 'data' => $nvp, 'paymentType' => $paymentType);
     } else {
         $response = array('success' => false, 'paymentType' => $paymentType, 'msg' => __("Invalid payment gateway", ET_DOMAIN));
     }
     /**
      * filter $response send to client after process payment
      *
      * @param Array $response
      * @param String $paymentType  The payment gateway user select
      * @param Array $order The order data
      *
      * @package  AE Payment
      * @category payment
      *
      * @since  1.0
      * @author  Dakachi
      */
     $response = apply_filters('ae_setup_payment', $response, $paymentType, $order);
     wp_send_json($response);
 }
Esempio n. 2
0
 /**
  * request a payment process et-setup-payment
  */
 function setup_payment()
 {
     global $user_ID;
     // remember to check isset or empty here
     $adID = isset($_POST['ID']) ? $_POST['ID'] : '';
     $author = isset($_POST['author']) ? $_POST['author'] : $user_ID;
     $packageID = isset($_POST['packageID']) ? $_POST['packageID'] : '';
     $paymentType = isset($_POST['paymentType']) ? $_POST['paymentType'] : '';
     $job_error = '';
     $author_error = '';
     $package_error = '';
     $errors = array();
     // job id invalid
     // author does not authorize job
     $job = get_post($adID);
     if ($author != $job->post_author && !current_user_can('manage_options')) {
         $author_error = __("Post author information is incorrect!", 'aecore-membership-backend');
         $errors[] = $author_error;
     }
     $plans = $this->get_plans();
     if (empty($plans)) {
         wp_send_json($response);
     }
     // input data error
     if (!empty($errors)) {
         $response = array('success' => false, 'errors' => $errors);
         wp_send_json($response);
     }
     ////////////////////////////////////////////////
     ////////////// process payment//////////////////
     ////////////////////////////////////////////////
     $order_data = array('payer' => $author, 'total' => '', 'status' => 'draft', 'payment' => $paymentType, 'paid_date' => '', 'payment_plan' => $packageID, 'post_parent' => $adID);
     foreach ($plans as $key => $value) {
         if ($value->sku == $packageID) {
             $plan = $value;
             break;
         }
     }
     $plan->ID = $adID;
     // $ship    =   array( 'street_address' => isset($company_location['full_location']) ? $company_location['full_location'] : __("No location", 'aecore-membership-backend'));
     // filter shipping
     $ship = apply_filters('ae_payment_ship', array());
     /**
      * filter order data
      */
     $order_data = apply_filters('ae_payment_order_data', $order_data);
     // insert order into database
     $order = new AE_Order($order_data, $ship);
     $order->add_product((array) $plan);
     $order_data = $order->generate_data_to_pay();
     et_write_session('order_id', $order_data['ID']);
     et_write_session('ad_id', $adID);
     $arg = apply_filters('ae_payment_links', array('return' => et_get_page_link('process-payment'), 'cancel' => et_get_page_link('process-payment')));
     /**
      * process payment
      */
     $paymentType = strtoupper($paymentType);
     /**
      * factory create payment visitor
      */
     $visitor = AE_Payment_Factory::createPaymentVisitor($paymentType, $order);
     $visitor->set_settings($arg);
     $nvp = $order->accept($visitor);
     if ($nvp['ACK']) {
         $response = array('success' => $nvp['ACK'], 'data' => $nvp, 'paymentType' => $paymentType);
     } else {
         $response = array('success' => false, 'paymentType' => $paymentType, 'msg' => __("Invalid payment gateway", 'aecore-membership-backend'));
     }
     $response = apply_filters('ae_setup_payment', $response, $paymentType, $order);
     wp_send_json($response);
 }
Esempio n. 3
0
/**
 * ae_process_payment function process payment return to check payment amount, update order
 * @use AE_Order , ET_NOPAYOrder, AE_Payment_Factory
 * @param string $payment_type the string of payment type such as paypal, 2checkout , stripe
 * @param Array $data
 *  -args $order_id : current order_id on process
 *  -args $ad_id : current ad id user submit
 * @return Array $payment_return
 *
 * @package AE Payment
 * @category payment
 *
 * @since 1.0
 * @author  Dakachi
 *
 */
function ae_process_payment($payment_type, $data)
{
    $payment_return = array('ACK' => false);
    if ($payment_type) {
        // check order id
        if (isset($data['order_id'])) {
            $order = new AE_Order($data['order_id']);
        } else {
            $order = new ET_NOPAYOrder();
        }
        // call a visitor process order base on payment type
        $visitor = AE_Payment_Factory::createPaymentVisitor(strtoupper($payment_type), $order, $payment_type);
        $payment_return = $order->accept($visitor);
        $data['order'] = $order;
        $data['payment_type'] = $payment_type;
        /**
         * filter payment return
         * @param Array $payment_return
         * @param Array $data -order : Order data, payment_type ...
         * @since 1.0
         */
        $payment_return = apply_filters('ae_process_payment', $payment_return, $data);
        $payment_return['order'] = $data['order'];
        /**
         * do an action after payment
         * @param Array $payment_return
         * @param Array $data -order : Order data, payment_type ...
         * @since 1.0
         */
        do_action('ae_process_payment_action', $payment_return, $data);
    }
    return $payment_return;
}