├── .gitignore ├── LICENSE ├── README.md ├── twocheckout ├── Twocheckout │ ├── TwocheckoutApi.php │ ├── TwocheckoutCharge.php │ ├── TwocheckoutError.php │ ├── TwocheckoutRequester.php │ └── TwocheckoutUtil.php ├── languages │ └── twocheckout.pot ├── twocheckout.png └── wc-twocheckout.php └── twocheckoutpp ├── languages └── twocheckoutpp.pot ├── paypal.png ├── twocheckout.png └── wc-twocheckoutpp.php /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.lock 3 | *.DS_Store 4 | *.swp 5 | *.out 6 | *.idea/* 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014 - Craig Christenson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### _[Signup free with 2Checkout and start selling!](https://www.2checkout.com/referral?r=git2co)_ 2 | 3 | ### Integrate WooCommerce with 2Checkout Payment API (Supports PayPal Direct) 4 | ---------------------------------------- 5 | 6 | ### 2Checkout Payment API Setup 7 | 8 | #### WooCommerce Settings 9 | 10 | 1. Copy the 'twocheckout' folder to your WordPress plugins directory under '/wp-content/plugins'. 11 | 2. In your WordPress admin, navigate to **Plugins** and install the **2Checkout Payment Gateway** plugin. 12 | 3. Navigate to your WooCommerce settings page, click on **Payment Gateways** and click the **Twocheckout** link. 13 | 4. Check to enable. 14 | 5. Enter the payment title and descriptino. 15 | 6. Enter your Seller ID (2Checkout Account Number). 16 | 7. Enter your 2Checkout API publishable key. 17 | 8. Enter your 2Checkout API private key. 18 | 9. Click 'Save Changes'. 19 | 20 | 21 | 22 | ### 2Checkout PayPal Direct Setup 23 | 24 | #### WooCommerce Settings 25 | 26 | 1. Copy the 'twocheckoutpp' folder to your WordPress plugins directory under '/wp-content/plugins'. 27 | 2. In your WordPress admin, navigate to **Plugins** and install the **2Checkout PayPal Direct Gateway** plugin. 28 | 3. Navigate to your WooCommerce settings page, click on **Payment Gateways** and click the **Twocheckoutpp** link. 29 | 4. Check to enable. 30 | 5. Enter the payment title and description. 31 | 6. Enter your Seller ID (2Checkout Account Number). 32 | 7. Enter your **Secret Word** _(Must be the same value entered on your 2Checkout Site Management page.)_ 33 | 9. Click **Save Changes**. 34 | 8. Save your changes. 35 | 36 | 37 | #### 2Checkout Settings 38 | 39 | 1. Sign in to your 2Checkout account. 40 | 2. Click the **Account** tab and **Site Management** subcategory. 41 | 3. Under **Direct Return** select **Header Redirect** or **Given links back to my website**. 42 | 4. Enter your **Secret Word**._(Must be the same value entered in your WooCommerce admin.)_ 43 | 5. Click **Save Changes**. 44 | 45 | Please feel free to contact 2Checkout directly with any integration questions. 46 | -------------------------------------------------------------------------------- /twocheckout/Twocheckout/TwocheckoutApi.php: -------------------------------------------------------------------------------- 1 | do_call($params); 10 | return Twocheckout_Util::return_resp($result); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /twocheckout/Twocheckout/TwocheckoutError.php: -------------------------------------------------------------------------------- 1 | code}]: {$this->message}\n"; 13 | } 14 | } -------------------------------------------------------------------------------- /twocheckout/Twocheckout/TwocheckoutRequester.php: -------------------------------------------------------------------------------- 1 | privateKey = TwocheckoutApi::$privateKey; 10 | $this->apiUrl = TwocheckoutApi::$apiUrl; 11 | } 12 | 13 | function do_call($data) 14 | { 15 | $data['privateKey'] = $this->privateKey; 16 | $data = json_encode($data); 17 | $header = array("content-type:application/JSON","content-length:".strlen($data)); 18 | $url = $this->apiUrl; 19 | $ch = curl_init($url); 20 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 21 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 22 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 23 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 24 | curl_setopt($ch, CURLOPT_TIMEOUT, 120); 25 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 26 | $resp = curl_exec($ch); 27 | curl_close($ch); 28 | if ($resp === FALSE) { 29 | throw new Twocheckout_Error("cURL call failed", "403"); 30 | } else { 31 | return $resp; 32 | } 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /twocheckout/Twocheckout/TwocheckoutUtil.php: -------------------------------------------------------------------------------- 1 | $data) 17 | { 18 | $array[$member]=$data; 19 | } 20 | return $array; 21 | } 22 | 23 | public static function checkError($contents) 24 | { 25 | if (isset($contents['exception'])) { 26 | throw new Twocheckout_Error($contents['exception']['errorMsg'], $contents['exception']['errorCode']); 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /twocheckout/languages/twocheckout.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Craig Christenson 2 | # This file is distributed under the same license as the 2Checkout Payment Gateway plugin. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: 2Checkout Payment Gateway 0.0.2\n" 6 | "Report-Msgid-Bugs-To: https://github.com/craigchristenson/woocommerce-2checkout-api/issues\n" 7 | "Last-Translator: FULL NAME \n" 8 | "Language-Team: LANGUAGE \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "POT-Creation-Date: 2020-06-15T07:16:15+00:00\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "X-Generator: WP-CLI 2.4.0\n" 15 | "X-Domain: twocheckout\n" 16 | 17 | #. Plugin Name of the plugin 18 | msgid "2Checkout Payment Gateway" 19 | msgstr "" 20 | 21 | #. Description of the plugin 22 | msgid "Allows you to use 2Checkout payment gateway with the WooCommerce plugin." 23 | msgstr "" 24 | 25 | #. Author of the plugin 26 | msgid "Craig Christenson" 27 | msgstr "" 28 | 29 | #. Author URI of the plugin 30 | msgid "https://www.2checkout.com" 31 | msgstr "" 32 | 33 | #: wc-twocheckout.php:114 34 | msgid "2Checkout" 35 | msgstr "" 36 | 37 | #: wc-twocheckout.php:115 38 | msgid "2Checkout - Credit Card/Paypal" 39 | msgstr "" 40 | 41 | #: wc-twocheckout.php:127 42 | msgid "Gateway Disabled" 43 | msgstr "" 44 | 45 | #: wc-twocheckout.php:127 46 | msgid "2Checkout does not support your store currency." 47 | msgstr "" 48 | 49 | #: wc-twocheckout.php:143 50 | msgid "Enable/Disable" 51 | msgstr "" 52 | 53 | #: wc-twocheckout.php:145 54 | msgid "Enable 2Checkout" 55 | msgstr "" 56 | 57 | #: wc-twocheckout.php:149 58 | msgid "Title" 59 | msgstr "" 60 | 61 | #: wc-twocheckout.php:151 62 | msgid "This controls the title which the user sees during checkout." 63 | msgstr "" 64 | 65 | #: wc-twocheckout.php:152 66 | msgid "Credit Card/PayPal" 67 | msgstr "" 68 | 69 | #: wc-twocheckout.php:156 70 | msgid "Description" 71 | msgstr "" 72 | 73 | #: wc-twocheckout.php:158 74 | msgid "This controls the description which the user sees during checkout." 75 | msgstr "" 76 | 77 | #: wc-twocheckout.php:159 78 | msgid "Pay with Credit Card/PayPal" 79 | msgstr "" 80 | 81 | #: wc-twocheckout.php:162 82 | msgid "Seller ID" 83 | msgstr "" 84 | 85 | #: wc-twocheckout.php:164 86 | msgid "Please enter your 2Checkout account number; this is needed in order to take payment." 87 | msgstr "" 88 | 89 | #: wc-twocheckout.php:170 90 | msgid "Publishable Key" 91 | msgstr "" 92 | 93 | #: wc-twocheckout.php:172 94 | msgid "Please enter your 2Checkout Publishable Key; this is needed in order to take payment." 95 | msgstr "" 96 | 97 | #: wc-twocheckout.php:178 98 | msgid "Private Key" 99 | msgstr "" 100 | 101 | #: wc-twocheckout.php:180 102 | msgid "Please enter your 2Checkout Private Key; this is needed in order to take payment." 103 | msgstr "" 104 | 105 | #: wc-twocheckout.php:186 106 | msgid "Sandbox/Production" 107 | msgstr "" 108 | 109 | #: wc-twocheckout.php:188 110 | msgid "Use 2Checkout Sandbox" 111 | msgstr "" 112 | 113 | #: wc-twocheckout.php:192 114 | msgid "Debug Log" 115 | msgstr "" 116 | 117 | #: wc-twocheckout.php:194 118 | msgid "Enable logging" 119 | msgstr "" 120 | 121 | #: wc-twocheckout.php:196 122 | msgid "Log 2Checkout events" 123 | msgstr "" 124 | 125 | #: wc-twocheckout.php:230 126 | msgid "Credit Card number" 127 | msgstr "" 128 | 129 | #: wc-twocheckout.php:239 130 | msgid "Expiration date" 131 | msgstr "" 132 | 133 | #: wc-twocheckout.php:241 134 | msgid "Month" 135 | msgstr "" 136 | 137 | #: wc-twocheckout.php:252 138 | msgid "Year" 139 | msgstr "" 140 | 141 | #: wc-twocheckout.php:265 142 | msgid "Card security code" 143 | msgstr "" 144 | 145 | #: wc-twocheckout.php:267 146 | msgid "3 or 4 digits usually found on the signature strip." 147 | msgstr "" 148 | -------------------------------------------------------------------------------- /twocheckout/twocheckout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/craigchristenson/woocommerce-2checkout-api/a248d6d74fe8ed51dc3a68c60c07a9489fbd04fd/twocheckout/twocheckout.png -------------------------------------------------------------------------------- /twocheckout/wc-twocheckout.php: -------------------------------------------------------------------------------- 1 | id = 'twocheckout'; 36 | $this->icon = apply_filters('woocommerce_twocheckout_icon', ''.$plugin_dir.'twocheckout.png'); 37 | $this->has_fields = true; 38 | 39 | // Load the settings 40 | $this->init_form_fields(); 41 | $this->init_settings(); 42 | 43 | // Define user set variables 44 | $this->title = $this->get_option('title'); 45 | $this->seller_id = $this->get_option('seller_id'); 46 | $this->publishable_key = $this->get_option('publishable_key'); 47 | $this->private_key = $this->get_option('private_key'); 48 | $this->description = $this->get_option('description'); 49 | $this->sandbox = $this->get_option('sandbox'); 50 | $this->debug = $this->get_option('debug'); 51 | 52 | self::$log_enabled = $this->debug; 53 | 54 | // Actions 55 | add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); 56 | 57 | // Save options 58 | add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 59 | 60 | // Payment listener/API hook 61 | add_action('woocommerce_api_wc_' . $this->id, array($this, 'check_ipn_response')); 62 | 63 | if (!$this->is_valid_for_use()){ 64 | $this->enabled = false; 65 | } 66 | } 67 | 68 | /** 69 | * Logging method 70 | * @param string $message 71 | */ 72 | public static function log( $message ) { 73 | if ( self::$log_enabled ) { 74 | if ( empty( self::$log ) ) { 75 | self::$log = new WC_Logger(); 76 | } 77 | self::$log->add( 'twocheckout', $message ); 78 | } 79 | } 80 | 81 | /** 82 | * Check if this gateway is enabled and available in the user's country 83 | * 84 | * @access public 85 | * @return bool 86 | */ 87 | function is_valid_for_use() { 88 | $supported_currencies = array( 89 | 'AFN', 'ALL', 'DZD', 'ARS', 'AUD', 'AZN', 'BSD', 'BDT', 'BBD', 90 | 'BZD', 'BMD', 'BOB', 'BWP', 'BRL', 'GBP', 'BND', 'BGN', 'CAD', 91 | 'CLP', 'CNY', 'COP', 'CRC', 'HRK', 'CZK', 'DKK', 'DOP', 'XCD', 92 | 'EGP', 'EUR', 'FJD', 'GTQ', 'HKD', 'HNL', 'HUF', 'INR', 'IDR', 93 | 'ILS', 'JMD', 'JPY', 'KZT', 'KES', 'LAK', 'MMK', 'LBP', 'LRD', 94 | 'MOP', 'MYR', 'MVR', 'MRO', 'MUR', 'MXN', 'MAD', 'NPR', 'TWD', 95 | 'NZD', 'NIO', 'NOK', 'PKR', 'PGK', 'PEN', 'PHP', 'PLN', 'QAR', 96 | 'RON', 'RUB', 'WST', 'SAR', 'SCR', 'SGF', 'SBD', 'ZAR', 'KRW', 97 | 'LKR', 'SEK', 'CHF', 'SYP', 'THB', 'TOP', 'TTD', 'TRY', 'UAH', 98 | 'AED', 'USD', 'VUV', 'VND', 'XOF', 'YER'); 99 | 100 | if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_twocheckout_supported_currencies', $supported_currencies ) ) ) return false; 101 | 102 | return true; 103 | } 104 | 105 | /** 106 | * Admin Panel Options 107 | * - Options for bits like 'title' and availability on a country-by-country basis 108 | * 109 | * @since 1.0.0 110 | */ 111 | public function admin_options() { 112 | 113 | ?> 114 |

115 |

116 | 117 | is_valid_for_use() ) : ?> 118 | 119 | 120 | generate_settings_html(); 123 | ?> 124 |
125 | 126 | 127 |

:

128 | form_fields = array( 142 | 'enabled' => array( 143 | 'title' => __( 'Enable/Disable', 'twocheckout' ), 144 | 'type' => 'checkbox', 145 | 'label' => __( 'Enable 2Checkout', 'twocheckout' ), 146 | 'default' => 'yes' 147 | ), 148 | 'title' => array( 149 | 'title' => __( 'Title', 'twocheckout' ), 150 | 'type' => 'text', 151 | 'description' => __( 'This controls the title which the user sees during checkout.', 'twocheckout' ), 152 | 'default' => __( 'Credit Card/PayPal', 'twocheckout' ), 153 | 'desc_tip' => true, 154 | ), 155 | 'description' => array( 156 | 'title' => __( 'Description', 'twocheckout' ), 157 | 'type' => 'textarea', 158 | 'description' => __( 'This controls the description which the user sees during checkout.', 'twocheckout' ), 159 | 'default' => __( 'Pay with Credit Card/PayPal', 'twocheckout' ) 160 | ), 161 | 'seller_id' => array( 162 | 'title' => __( 'Seller ID', 'twocheckout' ), 163 | 'type' => 'text', 164 | 'description' => __( 'Please enter your 2Checkout account number; this is needed in order to take payment.', 'twocheckout' ), 165 | 'default' => '', 166 | 'desc_tip' => true, 167 | 'placeholder' => '' 168 | ), 169 | 'publishable_key' => array( 170 | 'title' => __( 'Publishable Key', 'twocheckout' ), 171 | 'type' => 'text', 172 | 'description' => __( 'Please enter your 2Checkout Publishable Key; this is needed in order to take payment.', 'twocheckout' ), 173 | 'default' => '', 174 | 'desc_tip' => true, 175 | 'placeholder' => '' 176 | ), 177 | 'private_key' => array( 178 | 'title' => __( 'Private Key', 'twocheckout' ), 179 | 'type' => 'text', 180 | 'description' => __( 'Please enter your 2Checkout Private Key; this is needed in order to take payment.', 'twocheckout' ), 181 | 'default' => '', 182 | 'desc_tip' => true, 183 | 'placeholder' => '' 184 | ), 185 | 'sandbox' => array( 186 | 'title' => __( 'Sandbox/Production', 'twocheckout' ), 187 | 'type' => 'checkbox', 188 | 'label' => __( 'Use 2Checkout Sandbox', 'twocheckout' ), 189 | 'default' => 'no' 190 | ), 191 | 'debug' => array( 192 | 'title' => __( 'Debug Log', 'twocheckout' ), 193 | 'type' => 'checkbox', 194 | 'label' => __( 'Enable logging', 'twocheckout' ), 195 | 'default' => 'no', 196 | 'description' => sprintf( __( 'Log 2Checkout events', 'twocheckout' ), wc_get_log_file_path( 'twocheckout' ) ) 197 | ) 198 | ); 199 | 200 | } 201 | 202 | /** 203 | * Generate the credit card payment form 204 | * 205 | * @access public 206 | * @param none 207 | * @return string 208 | */ 209 | function payment_fields() { 210 | $plugin_dir = plugin_dir_url(__FILE__); 211 | // Description of payment method from settings 212 | if ($this->description) { ?> 213 |

description; ?> 215 |

217 | 218 | 221 | 222 |
223 | 224 | 225 | 226 | 227 | 228 | 229 |

230 | 231 | 232 | 233 |

234 | 235 |
236 | 237 | 238 |

239 | 240 | 251 | 260 |

261 |
262 | 263 | 264 |

265 | 266 | 267 | 268 |

269 | 270 |
271 | 272 |
273 | 274 | 342 | 343 | sandbox == 'yes'): ?> 344 | 345 | 346 | 347 | 348 | 349 | 350 | debug && $this->notify_url !=='') 365 | $this->log( 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: '. $this->notify_url ); 366 | 367 | // 2Checkout Args 368 | $twocheckout_args = array( 369 | 'token' => $_POST['token'], 370 | 'sellerId' => $this->seller_id, 371 | 'currency' => get_woocommerce_currency(), 372 | 'total' => $order->get_total(), 373 | 374 | // Order key 375 | 'merchantOrderId' => $order->get_order_number(), 376 | 377 | // Billing Address info 378 | "billingAddr" => array( 379 | 'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), 380 | 'addrLine1' => $order->get_billing_address_1(), 381 | 'addrLine2' => $order->get_billing_address_2(), 382 | 'city' => $order->get_billing_city(), 383 | 'state' => $order->get_billing_state(), 384 | 'zipCode' => $order->get_billing_postcode(), 385 | 'country' => $order->get_billing_country(), 386 | 'email' => $order->get_billing_email(), 387 | 'phoneNumber' => $order->get_billing_phone() 388 | ) 389 | ); 390 | 391 | try { 392 | if ($this->sandbox == 'yes') { 393 | TwocheckoutApi::setCredentials($this->seller_id, $this->private_key, 'sandbox'); 394 | } else { 395 | TwocheckoutApi::setCredentials($this->seller_id, $this->private_key); 396 | } 397 | $charge = Twocheckout_Charge::auth($twocheckout_args); 398 | if ($charge['response']['responseCode'] == 'APPROVED') { 399 | $order->payment_complete(); 400 | return array( 401 | 'result' => 'success', 402 | 'redirect' => $this->get_return_url( $order ) 403 | ); 404 | } 405 | } catch (Twocheckout_Error $e) { 406 | wc_add_notice($e->getMessage(), $notice_type = 'error' ); 407 | return; 408 | } 409 | } 410 | 411 | } 412 | 413 | include plugin_dir_path(__FILE__).'Twocheckout/TwocheckoutApi.php'; 414 | 415 | /** 416 | * Add the gateway to WooCommerce 417 | **/ 418 | function add_twocheckout_gateway($methods){ 419 | $methods[] = 'WC_Gateway_Twocheckout'; 420 | return $methods; 421 | } 422 | 423 | add_filter('woocommerce_payment_gateways', 'add_twocheckout_gateway'); 424 | 425 | } 426 | -------------------------------------------------------------------------------- /twocheckoutpp/languages/twocheckoutpp.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Craig Christenson 2 | # This file is distributed under the same license as the 2Checkout PayPal Direct Gateway plugin. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: 2Checkout PayPal Direct Gateway 0.0.2\n" 6 | "Report-Msgid-Bugs-To: https://github.com/craigchristenson/woocommerce-2checkout-api/issues\n" 7 | "Last-Translator: FULL NAME \n" 8 | "Language-Team: LANGUAGE \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "POT-Creation-Date: 2020-06-15T07:57:16+00:00\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "X-Generator: WP-CLI 2.4.0\n" 15 | "X-Domain: twocheckoutpp\n" 16 | 17 | #. Plugin Name of the plugin 18 | msgid "2Checkout PayPal Direct Gateway" 19 | msgstr "" 20 | 21 | #. Description of the plugin 22 | msgid "Allows you to use 2Checkout PayPal Direct payment method with the WooCommerce plugin." 23 | msgstr "" 24 | 25 | #. Author of the plugin 26 | msgid "Craig Christenson" 27 | msgstr "" 28 | 29 | #. Author URI of the plugin 30 | msgid "https://www.2checkout.com" 31 | msgstr "" 32 | 33 | #: wc-twocheckoutpp.php:101 34 | msgid "2Checkout PayPal" 35 | msgstr "" 36 | 37 | #: wc-twocheckoutpp.php:102 38 | msgid "2Checkout - Paypal" 39 | msgstr "" 40 | 41 | #: wc-twocheckoutpp.php:114 42 | msgid "Gateway Disabled" 43 | msgstr "" 44 | 45 | #: wc-twocheckoutpp.php:114 46 | msgid "2Checkout does not support your store currency." 47 | msgstr "" 48 | 49 | #: wc-twocheckoutpp.php:130 50 | msgid "Enable/Disable" 51 | msgstr "" 52 | 53 | #: wc-twocheckoutpp.php:132 54 | msgid "Enable 2Checkout PayPal" 55 | msgstr "" 56 | 57 | #: wc-twocheckoutpp.php:136 58 | msgid "Title" 59 | msgstr "" 60 | 61 | #: wc-twocheckoutpp.php:138 62 | msgid "This controls the title which the user sees during checkout." 63 | msgstr "" 64 | 65 | #: wc-twocheckoutpp.php:139 66 | msgid "PayPal" 67 | msgstr "" 68 | 69 | #: wc-twocheckoutpp.php:143 70 | msgid "Description" 71 | msgstr "" 72 | 73 | #: wc-twocheckoutpp.php:145 74 | msgid "This controls the description which the user sees during checkout." 75 | msgstr "" 76 | 77 | #: wc-twocheckoutpp.php:146 78 | msgid "Pay with PayPal" 79 | msgstr "" 80 | 81 | #: wc-twocheckoutpp.php:149 82 | msgid "Seller ID" 83 | msgstr "" 84 | 85 | #: wc-twocheckoutpp.php:151 86 | msgid "Please enter your 2Checkout account number." 87 | msgstr "" 88 | 89 | #: wc-twocheckoutpp.php:157 90 | msgid "Secret Word" 91 | msgstr "" 92 | 93 | #: wc-twocheckoutpp.php:159 94 | msgid "Please enter your 2Checkout Secret Word." 95 | msgstr "" 96 | 97 | #: wc-twocheckoutpp.php:165 98 | msgid "Debug Log" 99 | msgstr "" 100 | 101 | #: wc-twocheckoutpp.php:167 102 | msgid "Enable logging" 103 | msgstr "" 104 | 105 | #: wc-twocheckoutpp.php:169 106 | msgid "Log 2Checkout events" 107 | msgstr "" 108 | 109 | #: wc-twocheckoutpp.php:237 110 | msgid "Thank you for your order. We are now redirecting you to PayPal to make payment." 111 | msgstr "" 112 | 113 | #: wc-twocheckoutpp.php:260 114 | msgid "Pay via PayPal" 115 | msgstr "" 116 | 117 | #: wc-twocheckoutpp.php:260 118 | msgid "Cancel order & restore cart" 119 | msgstr "" 120 | 121 | #: wc-twocheckoutpp.php:295 122 | msgid "Thank you for your order, please click the button below to pay with PayPal." 123 | msgstr "" 124 | -------------------------------------------------------------------------------- /twocheckoutpp/paypal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/craigchristenson/woocommerce-2checkout-api/a248d6d74fe8ed51dc3a68c60c07a9489fbd04fd/twocheckoutpp/paypal.png -------------------------------------------------------------------------------- /twocheckoutpp/twocheckout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/craigchristenson/woocommerce-2checkout-api/a248d6d74fe8ed51dc3a68c60c07a9489fbd04fd/twocheckoutpp/twocheckout.png -------------------------------------------------------------------------------- /twocheckoutpp/wc-twocheckoutpp.php: -------------------------------------------------------------------------------- 1 | id = 'twocheckoutpp'; 36 | $this->icon = apply_filters('woocommerce_twocheckoutpp_icon', ''.$plugin_dir.'paypal.png'); 37 | $this->has_fields = true; 38 | 39 | // Load the settings 40 | $this->init_form_fields(); 41 | $this->init_settings(); 42 | 43 | // Define user set variables 44 | $this->title = $this->get_option('title'); 45 | $this->seller_id = $this->get_option('seller_id'); 46 | $this->secret_word = $this->get_option('secret_word'); 47 | $this->description = $this->get_option('description'); 48 | $this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Twocheckoutpp', home_url( '/' ) ) ); 49 | $this->debug = $this->get_option('debug'); 50 | 51 | self::$log_enabled = $this->debug; 52 | 53 | // Actions 54 | add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); 55 | 56 | // Save options 57 | add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 58 | 59 | // Payment listener/API hook 60 | add_action( 'woocommerce_api_wc_gateway_twocheckoutpp', array( $this, 'check_ipn_response' ) ); 61 | 62 | if (!$this->is_valid_for_use()){ 63 | $this->enabled = false; 64 | } 65 | } 66 | 67 | /** 68 | * Logging method 69 | * @param string $message 70 | */ 71 | public static function log( $message ) { 72 | if ( self::$log_enabled ) { 73 | if ( empty( self::$log ) ) { 74 | self::$log = new WC_Logger(); 75 | } 76 | self::$log->add( 'twocheckoutpp', $message ); 77 | } 78 | } 79 | 80 | /** 81 | * Check if this gateway is enabled and available in the user's country 82 | * 83 | * @access public 84 | * @return bool 85 | */ 86 | function is_valid_for_use() { 87 | if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_twocheckoutpp_supported_currencies', array('AUD', 'CAD','USD','EUR','GBP') ) ) ) return false; 88 | 89 | return true; 90 | } 91 | 92 | /** 93 | * Admin Panel Options 94 | * - Options for bits like 'title' and availability on a country-by-country basis 95 | * 96 | * @since 1.0.0 97 | */ 98 | public function admin_options() { 99 | 100 | ?> 101 |

102 |

103 | 104 | is_valid_for_use() ) : ?> 105 | 106 | 107 | generate_settings_html(); 110 | ?> 111 |
112 | 113 | 114 |

:

115 | form_fields = array( 129 | 'enabled' => array( 130 | 'title' => __( 'Enable/Disable', 'twocheckoutpp' ), 131 | 'type' => 'checkbox', 132 | 'label' => __( 'Enable 2Checkout PayPal', 'twocheckoutpp' ), 133 | 'default' => 'yes' 134 | ), 135 | 'title' => array( 136 | 'title' => __( 'Title', 'twocheckoutpp' ), 137 | 'type' => 'text', 138 | 'description' => __( 'This controls the title which the user sees during checkout.', 'twocheckoutpp' ), 139 | 'default' => __( 'PayPal', 'twocheckoutpp' ), 140 | 'desc_tip' => true, 141 | ), 142 | 'description' => array( 143 | 'title' => __( 'Description', 'twocheckoutpp' ), 144 | 'type' => 'textarea', 145 | 'description' => __( 'This controls the description which the user sees during checkout.', 'twocheckoutpp' ), 146 | 'default' => __( 'Pay with PayPal', 'twocheckoutpp' ) 147 | ), 148 | 'seller_id' => array( 149 | 'title' => __( 'Seller ID', 'twocheckoutpp' ), 150 | 'type' => 'text', 151 | 'description' => __( 'Please enter your 2Checkout account number.', 'twocheckoutpp' ), 152 | 'default' => '', 153 | 'desc_tip' => true, 154 | 'placeholder' => '' 155 | ), 156 | 'secret_word' => array( 157 | 'title' => __( 'Secret Word', 'twocheckoutpp' ), 158 | 'type' => 'text', 159 | 'description' => __( 'Please enter your 2Checkout Secret Word.', 'twocheckoutpp' ), 160 | 'default' => '', 161 | 'desc_tip' => true, 162 | 'placeholder' => '' 163 | ), 164 | 'debug' => array( 165 | 'title' => __( 'Debug Log', 'twocheckoutpp' ), 166 | 'type' => 'checkbox', 167 | 'label' => __( 'Enable logging', 'twocheckoutpp' ), 168 | 'default' => 'no', 169 | 'description' => sprintf( __( 'Log 2Checkout events', 'twocheckoutpp' ), wc_get_log_file_path( 'twocheckoutpp' ) ) 170 | ) 171 | ); 172 | 173 | } 174 | 175 | /** 176 | * Get 2Checkout Args 177 | * 178 | * @access public 179 | * @param mixed $order 180 | * @return array 181 | */ 182 | function get_twocheckout_args( $order ) { 183 | global $woocommerce; 184 | 185 | $order_id = $order->id; 186 | 187 | if ( 'yes' == $this->debug ) 188 | $this->log('Generating payment form for order ' . $order->get_order_number()); 189 | 190 | $twocheckout_args = array(); 191 | 192 | $twocheckout_args['sid'] = $this->seller_id; 193 | $twocheckout_args['paypal_direct'] = 'Y'; 194 | $twocheckout_args['cart_order_id'] = $order_id; 195 | $twocheckout_args['merchant_order_id'] = $order_id; 196 | $twocheckout_args['total'] = $order->get_total(); 197 | $twocheckout_args['return_url'] = $order->get_cancel_order_url(); 198 | $twocheckout_args['x_receipt_link_url'] = $this->notify_url; 199 | $twocheckout_args['currency_code'] = get_woocommerce_currency(); 200 | $twocheckout_args['card_holder_name'] = $order->billing_first_name . ' ' . $order->billing_last_name; 201 | $twocheckout_args['street_address'] = $order->billing_address_1; 202 | $twocheckout_args['street_address2'] = $order->billing_address_2; 203 | $twocheckout_args['city'] = $order->billing_city; 204 | $twocheckout_args['state'] = $order->billing_state; 205 | $twocheckout_args['country'] = $order->billing_country; 206 | $twocheckout_args['zip'] = $order->billing_postcode; 207 | $twocheckout_args['phone'] = $order->billing_phone; 208 | $twocheckout_args['email'] = $order->billing_email; 209 | 210 | $twocheckout_args = apply_filters( 'woocommerce_twocheckoutpp_args', $twocheckout_args ); 211 | 212 | return $twocheckout_args; 213 | } 214 | 215 | /** 216 | * Generate the twocheckout button link 217 | * 218 | * @access public 219 | * @param mixed $order_id 220 | * @return string 221 | */ 222 | function generate_twocheckout_form( $order_id ) { 223 | global $woocommerce; 224 | 225 | $order = new WC_Order( $order_id ); 226 | 227 | $twocheckout_args = $this->get_twocheckout_args( $order ); 228 | 229 | $twocheckout_args_array = array(); 230 | 231 | foreach ($twocheckout_args as $key => $value) { 232 | $twocheckout_args_array[] = ''; 233 | } 234 | 235 | wc_enqueue_js( ' 236 | jQuery("body").block({ 237 | message: "' . esc_js( __( 'Thank you for your order. We are now redirecting you to PayPal to make payment.', 'twocheckoutpp' ) ) . '", 238 | baseZ: 99999, 239 | overlayCSS: 240 | { 241 | background: "#fff", 242 | opacity: 0.6 243 | }, 244 | css: { 245 | padding: "20px", 246 | zindex: "9999999", 247 | textAlign: "center", 248 | color: "#555", 249 | border: "3px solid #aaa", 250 | backgroundColor:"#fff", 251 | cursor: "wait", 252 | lineHeight: "24px", 253 | } 254 | }); 255 | jQuery("#submit_twocheckout_payment_form").click(); 256 | ' ); 257 | 258 | return '
259 | ' . implode( '', $twocheckout_args_array) . ' 260 | '.__( 'Cancel order & restore cart', 'twocheckoutpp' ).' 261 |
'; 262 | 263 | } 264 | 265 | /** 266 | * Process the payment and return the result 267 | * 268 | * @access public 269 | * @param int $order_id 270 | * @return array 271 | */ 272 | function process_payment( $order_id ) { 273 | global $woocommerce; 274 | 275 | $order = new WC_Order($order_id); 276 | 277 | if ( 'yes' == $this->debug ) 278 | $this->log( 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url ); 279 | 280 | return array( 281 | 'result' => 'success', 282 | 'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id('pay' )))) 283 | ); 284 | 285 | } 286 | 287 | /** 288 | * Output for the order received page. 289 | * 290 | * @access public 291 | * @return void 292 | */ 293 | function receipt_page( $order ) { 294 | 295 | echo '

'.__( 'Thank you for your order, please click the button below to pay with PayPal.', 'twocheckoutpp' ).'

'; 296 | 297 | echo $this->generate_twocheckout_form( $order ); 298 | 299 | } 300 | 301 | /** 302 | * Check for 2Checkout Response 303 | * 304 | * @access public 305 | * @return void 306 | */ 307 | function check_ipn_response() { 308 | global $woocommerce; 309 | @ob_clean(); 310 | 311 | $wc_order_id = $_REQUEST['merchant_order_id']; 312 | 313 | $compare_string = $this->secret_word . $this->seller_id . $_REQUEST['order_number'] . $_REQUEST['total']; 314 | $compare_hash1 = strtoupper(md5($compare_string)); 315 | $compare_hash2 = $_REQUEST['key']; 316 | if ($compare_hash1 != $compare_hash2) { 317 | wp_die( "2Checkout Hash Mismatch... check your secret word." ); 318 | } else { 319 | $wc_order = new WC_Order( absint( $wc_order_id ) ); 320 | 321 | // Mark order complete 322 | $wc_order->payment_complete(); 323 | 324 | // Empty cart and clear session 325 | $woocommerce->cart->empty_cart(); 326 | 327 | wp_redirect( $this->get_return_url( $wc_order ) ); 328 | exit; 329 | } 330 | 331 | } 332 | 333 | } 334 | 335 | /** 336 | * Add the gateway to WooCommerce 337 | **/ 338 | function add_twocheckoutpp_gateway($methods){ 339 | $methods[] = 'WC_Gateway_Twocheckoutpp'; 340 | return $methods; 341 | } 342 | 343 | add_filter('woocommerce_payment_gateways', 'add_twocheckoutpp_gateway'); 344 | 345 | } 346 | --------------------------------------------------------------------------------