コード例 #1
0
ファイル: Extension.php プロジェクト: daanbakker1995/vanteun
 /**
  * Update lead status of the specified payment
  *
  * @param Pronamic_Pay_Payment $payment
  */
 public static function status_update(Pronamic_Pay_Payment $payment, $can_redirect = false)
 {
     $source_id = $payment->get_source_id();
     $order = new WC_Order((int) $source_id);
     $gateway = new Pronamic_WP_Pay_Extensions_WooCommerce_IDealGateway();
     $data = new Pronamic_WP_Pay_Extensions_WooCommerce_PaymentData($order, $gateway);
     // Only update if order is not 'processing' or 'completed'
     // @see https://github.com/woothemes/woocommerce/blob/v2.0.0/classes/class-wc-order.php#L1279
     $should_update = !Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::order_has_status($order, array(Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::ORDER_STATUS_COMPLETED, Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::ORDER_STATUS_PROCESSING));
     // Defaults
     $status = null;
     $url = $data->get_normal_return_url();
     $status = $payment->get_status();
     $payment_method_title = $order->payment_method_title;
     switch ($status) {
         case Pronamic_WP_Pay_Statuses::CANCELLED:
             $url = $data->get_cancel_url();
             break;
         case Pronamic_WP_Pay_Statuses::EXPIRED:
             if ($should_update) {
                 $note = sprintf('%s %s.', $payment_method_title, __('payment expired', 'pronamic_ideal'));
                 // WooCommerce PayPal gateway uses 'failed' order status for an 'expired' payment
                 // @see http://plugins.trac.wordpress.org/browser/woocommerce/tags/1.5.4/classes/gateways/class-wc-paypal.php#L557
                 $order->update_status(Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::ORDER_STATUS_FAILED, $note);
             }
             $url = $data->get_error_url();
             break;
         case Pronamic_WP_Pay_Statuses::FAILURE:
             if ($should_update) {
                 $note = sprintf('%s %s.', $payment_method_title, __('payment failed', 'pronamic_ideal'));
                 $order->update_status(Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::ORDER_STATUS_FAILED, $note);
             }
             $url = $data->get_error_url();
             break;
         case Pronamic_WP_Pay_Statuses::SUCCESS:
             if ($should_update) {
                 // Payment completed
                 $order->add_order_note(sprintf('%s %s.', $payment_method_title, __('payment completed', 'pronamic_ideal')));
                 // Mark order complete
                 $order->payment_complete();
             }
             $url = $data->get_success_url();
             break;
         case Pronamic_WP_Pay_Statuses::OPEN:
             if ($should_update) {
                 $order->add_order_note(sprintf('%s %s.', $payment_method_title, __('payment open', 'pronamic_ideal')));
             }
             break;
         default:
             if ($should_update) {
                 $order->add_order_note(sprintf('%s %s.', $payment_method_title, __('payment unknown', 'pronamic_ideal')));
             }
             break;
     }
     if ($can_redirect) {
         wp_redirect($url);
         exit;
     }
 }
コード例 #2
0
 /**
  * Get description
  *
  * @see Pronamic_Pay_PaymentDataInterface::get_description()
  * @return string
  */
 public function get_description()
 {
     // @see https://github.com/woothemes/woocommerce/blob/v2.0.19/classes/emails/class-wc-email-new-order.php
     $find = array();
     $replace = array();
     $find[] = '{blogname}';
     $replace[] = $this->get_blogname();
     $find[] = '{site_title}';
     $replace[] = $this->get_blogname();
     $find[] = '{order_date}';
     $replace[] = date_i18n(Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::get_date_format(), strtotime($this->order->order_date));
     $find[] = '{order_number}';
     $replace[] = $this->order->get_order_number();
     // Description
     $description = str_replace($find, $replace, $this->description);
     return $description;
 }
コード例 #3
0
ファイル: Gateway.php プロジェクト: daanbakker1995/vanteun
 /**
  * Process iDEAL advanced payment
  *
  * @param WC_Order $order
  * @return array
  */
 private function process_gateway_http_redirect($order, $gateway)
 {
     $data = new Pronamic_WP_Pay_Extensions_WooCommerce_PaymentData($order, $this, $this->payment_description);
     $payment = Pronamic_WP_Pay_Plugin::start($this->config_id, $gateway, $data, $this->payment_method);
     $error = $gateway->get_error();
     if (is_wp_error($error)) {
         Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::add_notice(Pronamic_WP_Pay_Plugin::get_default_error_message(), 'error');
         foreach ($error->get_error_messages() as $message) {
             Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::add_notice($message, 'error');
         }
         // @see https://github.com/woothemes/woocommerce/blob/v1.6.6/woocommerce-functions.php#L518
         // @see https://github.com/woothemes/woocommerce/blob/v2.1.5/includes/class-wc-checkout.php#L669
         return array('result' => 'failure');
     } else {
         $url = $payment->get_action_url();
         return array('result' => 'success', 'redirect' => $url);
     }
 }