/** * Entry point of the plugin. * Checks if Woocommerce is active, autoloads classes and initializes the plugin. */ function paypro_plugin_init() { // Check if WooCommerce is active if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) || class_exists('WooCommerce')) { PayPro_WC_Autoload::register(); PayPro_WC_Plugin::init(); } }
/** * Initalizes the plugin */ public static function init() { if (self::$initialized) { return; } // Add filters and actions add_filter('woocommerce_payment_gateways_settings', array(__CLASS__, 'addSettingsFields')); add_filter('woocommerce_payment_gateways', array(__CLASS__, 'addGateways')); add_action('woocommerce_api_paypro_return', array(__CLASS__, 'onReturn')); add_action('woocommerce_api_paypro_cancel', array(__CLASS__, 'onCancel')); add_action('admin_notices', array(__CLASS__, 'addApiKeyReminder')); // Initialize all PayPro classes we need self::$settings = new PayPro_WC_Settings(); self::$woocommerce = new PayPro_WC_Woocommerce(); self::$wc_api = new PayPro_WC_Api(); self::$paypro_api = new PayProApiHelper(); self::$paypro_api->init(self::$settings->apiKey(), self::$settings->testMode()); $initialized = true; }
/** * Get PayPro sale status from payment hash * Only usable on an WooCommerce API call */ public function getSaleStatusFromPaymentHashes($payment_hashes) { // Get status of this order from PayPro API $results = array(); foreach ($payment_hashes as $payment_hash) { $result = PayPro_WC_Plugin::$paypro_api->getSaleStatus($payment_hash); if ($result['errors']) { PayPro_WC_Plugin::debug(__CLASS__ . ': Failed to get sale status from PayPro API - message: ' . $result['message'] . ', payment_hash: ' . $payment_hash); } else { array_push($results, array('hash' => $payment_hash, 'status' => $result['data']['current_status'])); } } // Could not get status, so throw and log if (empty($results)) { header(' ', true, 500); PayPro_WC_Plugin::debug(__CLASS__ . ': Could not get the status for these payment hashes: ' . implode(', ', $payment_hashes)); exit; } return $this->determineSaleStatus($results); }
/** * Returns the order status setting for when a payment has been completed */ public function paymentCompleteStatus() { return trim(get_option(PayPro_WC_Plugin::getSettingId('payment-complete-status'))); }
/** * Returns the icon url for this gateway */ protected function getIconUrl() { return PayPro_WC_Plugin::getPluginUrl('assets/images/' . $this->id . '.png'); }