コード例 #1
0
 /**
  * Process payment
  *
  * @param int $order_id
  *
  * @return array
  */
 public function process_payment($order_id)
 {
     $order = wc_get_order($order_id);
     $config = $this->settings;
     try {
         $payment_api = $this->get_api();
         $request = new WC_LUUP_API_Transaction_Request($config, $order);
         // Only accept specific currencies
         if ($this->get_option('currencies_accepted')) {
             $request->set_currencies_accepted($this->get_option('currencies_accepted'));
         }
         $request->set_payment_brand(self::PAYMENT_BRAND)->set_payment_type($this->get_option('auth_mode'))->set_shopper_result_url(WC()->api_request_url('WC_LUUP_PayPal'));
         $payment_response = $payment_api->send_payment($request);
     } catch (Exception $e) {
         //todo - log exception
         wc_add_notice('Sorry there was a problem connecting to PayPal, please try again.', 'error');
         return false;
     }
     return array('result' => 'success', 'redirect' => $payment_response->process_async_redirect());
 }
コード例 #2
0
 /**
  * Receipt/Payment Page
  *
  * @param $order_id
  */
 public function receipt_page($order_id)
 {
     $error = false;
     $payment_form = null;
     $order = wc_get_order($order_id);
     $config = $this->settings;
     try {
         $payment_api = $this->get_api();
         $request = new WC_LUUP_API_Transaction_Request($config, $order);
         // Only accept specific currencies
         if ($this->get_option('currencies_accepted')) {
             $request->set_currencies_accepted($this->get_option('currencies_accepted'));
         }
         $request->set_payment_type($this->get_option('auth_mode'))->set_create_registration(true);
         $checkout_response = $payment_api->prepare_checkout($request);
     } catch (Exception $e) {
         //todo - log exception
         $error = true;
     }
     if (!$error) {
         $checkout_response_data = $checkout_response->to_array();
         if ($checkout_response->is_success()) {
             $checkout_id = $checkout_response_data->id;
             $brands_accepted = $this->get_option('brands_accepted');
             $return_url = WC()->api_request_url(get_class($this));
             $locale = str_replace('_', '-', get_locale());
             $payment_form = $payment_api->create_payment_form($checkout_id, $return_url, $brands_accepted, $locale);
         } else {
             $error = true;
         }
     }
     //		if ( $error ) {
     //			wc_add_notice( 'There was a problem connecting to the payment server, please try again', 'error' );
     //			wp_redirect( wc_get_page_permalink( 'cart' ) );
     //		}
     echo WC_LUUP_Base_Helper::render_view('payment-form', array('error' => $error, 'order' => $order, 'payment_form' => $payment_form));
 }