Changeset 2737508
- Timestamp:
- 06/05/2022 04:18:06 AM (4 years ago)
- Location:
- swipe-for-woocommerce/trunk
- Files:
-
- 4 edited
-
README.md (modified) (1 diff)
-
admin/class-swipego-wc-settings.php (modified) (1 diff)
-
includes/class-swipego-wc-gateway.php (modified) (8 diffs)
-
libraries/swipego/includes/abstracts/abstract-swipego-client.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
swipe-for-woocommerce/trunk/README.md
r2724952 r2737508 1 # f70-woocommerce 1 ## Swipe for WooCommerce 2 Contributors: teamswipe 3 Tags: swipe, woocommerce, payment 4 Requires at least: 4.6 5 Tested up to: 5.9.2 6 Stable tag: 1.0.0 7 Requires PHP: 7.0 8 License: GPLv2 or later 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 2 10 3 4 5 ## Getting started 6 7 To make it easy for you to get started with GitLab, here's a list of recommended next steps. 8 9 Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! 10 11 ## Add your files 12 13 - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files 14 - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: 15 16 ``` 17 cd existing_repo 18 git remote add origin https://gitlab.com/fintechww/f70-woocommerce.git 19 git branch -M main 20 git push -uf origin main 21 ``` 22 23 ## Integrate with your tools 24 25 - [ ] [Set up project integrations](https://gitlab.com/fintechww/f70-woocommerce/-/settings/integrations) 26 27 ## Collaborate with your team 28 29 - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) 30 - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) 31 - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) 32 - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) 33 - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) 34 35 ## Test and Deploy 36 37 Use the built-in continuous integration in GitLab. 38 39 - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) 40 - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) 41 - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) 42 - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) 43 - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) 44 45 *** 46 47 # Editing this README 48 49 When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. 50 51 ## Suggestions for a good README 52 Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. 53 54 ## Name 55 Choose a self-explaining name for your project. 11 Accept credit card, online banking and e-wallet directly on your store with the Swipe payment gateway for WooCommerce. 56 12 57 13 ## Description 58 Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.59 14 60 ## Badges 61 On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. 15 ### Swipe for WooCommerce 62 16 63 ## Visuals 64 Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. 17 Accept credit card, online banking and e-wallet directly on your store with the Swipe payment gateway for WooCommerce. 18 19 #### Credit Card 20 Visa 21 MasterCard 22 23 #### FPX Online Banking 24 Affin Bank 25 AGRONet 26 Alliance Bank 27 AmBank 28 Bank Islam 29 Bank Muamalat 30 Bank Rakyat 31 BSN 32 CIMB Clicks 33 Hong Leong Bank 34 HSBC Bank 35 KFH 36 Maybank2E 37 Maybank2U 38 OCBC Bank 39 Public Bank 40 RHB Bank 41 Standard Chartered 42 UOB Bank 43 44 #### e-Wallet 45 Coming Soon 46 47 #### SWIPE INTRODUCTION 48 Swipe is a complete payment platform for businesses. 49 50 We help businesses to accept, manage and distribute payment worldwide and is ready to be adopted by companies ranging from startups to large corporations. 51 52 #### WHY CHOOSE SWIPE? 53 Swipe has no setup fees, no monthly fees, no hidden costs: you only get charged when you earn money! Earnings are transferred to your bank account on a 3-day rolling basis. 54 55 #### WEB PAYMENTS API SUPPORT 56 Swipe for WooCommerce includes Web Payments API support, allowing customers to pay using payment information associated with their mobile devices in browsers that support the Web Payments API (Chrome for Android, amongst others). On mobile, checkout is now just a few taps away. 57 58 #### SWIPE API SYNC 59 Swipe introduces a new way to integrate our platform with your stores in less than 1 min. You no longer have to worry about where to get the API Access Key or API Signature Key from the payment platform. We have you covered! 60 61 The new technology helps non-technical or first time users to integrate with our payment platform with your login details only. We help to fetch the API keys automatically and you just have to install our plugin. It is that simple! [Watch this video](https://www.youtube.com/watch?v=9mhcNP-xKWg) 65 62 66 63 ## Installation 67 Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.68 64 69 ## Usage 70 Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. 65 #### GET STARTED SWIPE FOR WOOCOMMERCE 71 66 72 ## Support 73 Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. 67 Step for existing Swipe users: 68 1. Install and activate your WooCommerce. 69 2. Login your Swipe account. 70 3. Choose your business. 71 4. Start accepting payment. 74 72 75 ## Roadmap 76 If you have ideas for releases in the future, it is a good idea to list them in the README. 73 Step for new Swipe users: 74 1. [Create your Swipe account](https://app.swipego.io/register). 75 2. Add your business. 76 3. Install and activate your WooCommerce. 77 4. Login your Swipe account. 78 5. Choose your business. 79 6. Start accepting payment. 77 80 78 ## Contributing 79 State if you are open to contributions and what your requirements are for accepting them. 81 How to use WooCommerce plugin with Swipe: 82 1. Install and activate your WooCommerce. 83 Notes: You do not have to configure Swipe at WooCommerce, we have configured everything. 80 84 81 For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. 85 Video Tutorial > [Payment Integration for WooCommerce](https://www.youtube.com/watch?v=9mhcNP-xKWg) - Swipe 82 86 83 You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. 87 Explore us: [www.swipego.io](https://www.swipego.io) 84 88 85 ## Authors and acknowledgment 86 Show your appreciation to those who have contributed to the project. 89 Social Media: [Facebook](https://www.facebook.com/swipego/) 87 90 88 ## License 89 For open source projects, say how it is licensed. 91 ## Changelog 90 92 91 ## Project status 92 If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. 93 = 1.0.0 - 2022-04-11 = 94 - Initial release of the plugin -
swipe-for-woocommerce/trunk/admin/class-swipego-wc-settings.php
r2724952 r2737508 281 281 $params = array( 282 282 'name' => 'payment.created', 283 'url' => WC()->api_request_url( get_class( $this )),283 'url' => WC()->api_request_url( 'swipego_wc_gateway' ), 284 284 'enabled' => true, 285 285 ); -
swipe-for-woocommerce/trunk/includes/class-swipego-wc-gateway.php
r2724952 r2737508 1 1 <?php 2 if ( !defined( 'ABSPATH' ) ) exit; 3 4 class Swipego_WC_Gateway extends WC_Payment_Gateway { 2 if (!defined('ABSPATH')) exit; 3 4 class Swipego_WC_Gateway extends WC_Payment_Gateway 5 { 5 6 6 7 private $swipego; … … 12 13 private $debug; 13 14 14 public function __construct() { 15 public function __construct() 16 { 15 17 16 18 $this->id = 'swipego'; 17 $this->method_title = __( 'Swipe', 'swipego-wc');18 $this->method_description = __( 'Enable Swipe payment gateway for your site.', 'swipego-wc');19 $this->order_button_text = __( 'Pay with Swipe', 'swipego-wc');20 $this->supports = array( 'products');21 22 $this->title = $this->get_option( 'title' ) . __( ' Swipe', 'swipego-wc');23 $this->description = $this->get_option( 'description');19 $this->method_title = __('Swipe', 'swipego-wc'); 20 $this->method_description = __('Enable Swipe payment gateway for your site.', 'swipego-wc'); 21 $this->order_button_text = __('Pay with Swipe', 'swipego-wc'); 22 $this->supports = array('products'); 23 24 $this->title = $this->get_option('title') . __(' Swipe', 'swipego-wc'); 25 $this->description = $this->get_option('description'); 24 26 $this->icon = SWIPEGO_URL . 'assets/images/logo-swipe.svg'; 25 27 26 $this->api_key = $this->get_option( 'api_key');27 $this->signature_key = $this->get_option( 'signature_key');28 $this->business_id = $this->get_option( 'business_id');29 $this->environment = $this->get_option( 'environment');30 $this->debug = $this->get_option( 'debug') === 'yes' ? true : false;28 $this->api_key = $this->get_option('api_key'); 29 $this->signature_key = $this->get_option('signature_key'); 30 $this->business_id = $this->get_option('business_id'); 31 $this->environment = $this->get_option('environment'); 32 $this->debug = $this->get_option('debug') === 'yes' ? true : false; 31 33 32 34 $this->register_hooks(); 33 35 34 36 // Check if the payment gateway is ready to use 35 if ( !$this->validate_required_settings()) {37 if (!$this->validate_required_settings()) { 36 38 $this->enabled = 'no'; 37 39 } 38 40 39 41 $this->init_api(); 40 41 42 } 42 43 43 44 // Register WooCommerce payment gateway hooks 44 private function register_hooks() { 45 46 add_action( 'woocommerce_api_' . $this->id . '_wc_gateway', array( $this, 'handle_ipn' ) ); 47 48 } 45 private function register_hooks() 46 { 47 48 add_action('woocommerce_api_' . $this->id . '_wc_gateway', array($this, 'handle_ipn')); 49 add_action('woocommerce_thankyou', array($this, 'add_thank_you_page_transaction_id')); 50 } 51 52 function add_thank_you_page_transaction_id($order_id) 53 { 54 55 $payment_id = isset($_GET['payment_id']) ? sanitize_text_field($_GET['payment_id']) : null; 56 57 if ($payment_id) { 58 echo "<script> \n"; 59 echo "var ul = document.getElementsByClassName('woocommerce-thankyou-order-details') \n"; 60 echo "var li = document.createElement('li') \n"; 61 echo "var label = document.createTextNode('Transaction ID:') \n"; 62 echo "var value = document.createElement('strong') \n"; 63 echo "value.innerHTML = " . $payment_id . "\n"; 64 echo "li.append(label) \n"; 65 echo "li.append(value) \n"; 66 echo "ul[0].appendChild(li) \n"; 67 echo "</script> \n"; 68 } 69 } 70 49 71 50 72 // Check if all required settings is filled 51 private function validate_required_settings() { 73 private function validate_required_settings() 74 { 52 75 return $this->api_key 53 76 && $this->signature_key … … 56 79 57 80 // Initialize API 58 private function init_api() { 81 private function init_api() 82 { 59 83 $this->swipego = new Swipego_WC_API(); 60 84 } 61 85 62 86 // Process the payment 63 public function process_payment( $order_id ) { 64 65 if ( !$this->validate_required_settings() ) { 66 return false; 67 } 68 69 if ( !$order = wc_get_order( $order_id ) ) { 87 public function process_payment($order_id) 88 { 89 90 if (!$this->validate_required_settings()) { 91 return false; 92 } 93 94 if (!$order = wc_get_order($order_id)) { 70 95 return false; 71 96 } … … 73 98 try { 74 99 // Redirect to the payment page if the transaction ID has been saved 75 if ( $transaction_id = get_post_meta( $order_id, '_transaction_id', true )) {76 77 if ( $payment_url = $this->get_payment_link( $transaction_id )) {100 if ($transaction_id = get_post_meta($order_id, '_transaction_id', true)) { 101 102 if ($payment_url = $this->get_payment_link($transaction_id)) { 78 103 return array( 79 104 'result' => 'success', … … 83 108 } 84 109 85 swipego_wc_logger( 'Creating payment for order #' . $order_id);110 swipego_wc_logger('Creating payment for order #' . $order_id); 86 111 87 112 $params = array( … … 90 115 'amount' => (float) $order->get_total(), 91 116 'title' => get_bloginfo(), 92 'phone_no' => preg_replace('/[^0-9]/', '', $order->get_billing_phone() ),93 'description' => sprintf( __( 'Payment for Order #%d', 'swipego-wc' ), $order_id),94 'redirect_url' => $this->get_return_url( $order),117 'phone_no' => preg_replace('/[^0-9]/', '', $order->get_billing_phone()), 118 'description' => sprintf(__('Payment for Order #%d', 'swipego-wc'), $order_id), 119 'redirect_url' => $this->get_return_url($order), 95 120 'reference' => $order->get_id(), 96 121 'reference_2' => 'woocommerce', … … 98 123 ); 99 124 100 list( $code, $response ) = $this->swipego->create_payment_link( $params);101 102 $errors = isset( $response['errors']) ? $response['errors'] : false;103 104 if ( $errors) {105 foreach ( $errors as $error) {106 throw new Exception( $error[0]);125 list($code, $response) = $this->swipego->create_payment_link($params); 126 127 $errors = isset($response['errors']) ? $response['errors'] : false; 128 129 if ($errors) { 130 foreach ($errors as $error) { 131 throw new Exception($error[0]); 107 132 } 108 133 } 109 134 110 swipego_wc_logger( 'Payment created for order #' . $order_id);111 112 if ( isset( $response['data']['_id'] )) {113 update_post_meta( $order->get_id(), '_transaction_id', wc_clean( $response['data']['_id'] ));135 swipego_wc_logger('Payment created for order #' . $order_id); 136 137 if (isset($response['data']['_id'])) { 138 update_post_meta($order->get_id(), '_transaction_id', wc_clean($response['data']['_id'])); 114 139 } 115 140 116 141 // Redirect to the payment page 117 if ( isset( $response['data']['payment_url'] )) {142 if (isset($response['data']['payment_url'])) { 118 143 return array( 119 144 'result' => 'success', … … 121 146 ); 122 147 } 123 124 } catch ( Exception $e ) { 125 wc_add_notice( __( 'Payment error: ', 'swipego-wc' ) . $e->getMessage(), 'error' ); 148 } catch (Exception $e) { 149 wc_add_notice(__('Payment error: ', 'swipego-wc') . $e->getMessage(), 'error'); 126 150 } 127 151 128 152 return; 129 130 153 } 131 154 132 155 // Get payment link based on bill ID saved in the WooCommerce 133 private function get_payment_link( $transaction_id ) { 156 private function get_payment_link($transaction_id) 157 { 134 158 135 159 try { 136 160 137 list( $code, $response ) = $this->swipego->get_payment_link( $transaction_id);138 139 $errors = isset( $response['errors']) ? $response['errors'] : false;140 141 if ( $errors) {142 foreach ( $errors as $error) {143 throw new Exception( $error[0]);161 list($code, $response) = $this->swipego->get_payment_link($transaction_id); 162 163 $errors = isset($response['errors']) ? $response['errors'] : false; 164 165 if ($errors) { 166 foreach ($errors as $error) { 167 throw new Exception($error[0]); 144 168 } 145 169 } 146 170 147 if ( isset( $response['data']['payment_url'] )) {171 if (isset($response['data']['payment_url'])) { 148 172 return $response['data']['payment_url']; 149 173 } 150 151 } catch ( Exception $e ) {}174 } catch (Exception $e) { 175 } 152 176 153 177 return false; 154 155 178 } 156 179 157 180 // Handle IPN 158 public function handle_ipn() { 181 public function handle_ipn() 182 { 159 183 160 184 $response = $this->swipego->get_ipn_response(); 161 185 162 if ( !$response) {163 swipego_wc_logger( 'IPN webhook failed');164 wp_die( 'Swipe IPN webhook failed', 'Swipe IPN', array( 'response' => 200 ));165 } 166 167 swipego_wc_logger( 'IPN webhook response: ' . wp_json_encode( $response ));168 169 if ( $response['payment_link_reference_2'] !== 'woocommerce') {170 return false; 171 } 172 173 $order_id = absint( $response['payment_link_reference']);174 $order = wc_get_order( $order_id);175 176 if ( !$order) {177 swipego_wc_logger( 'Order #' . $order_id . ' not found');186 if (!$response) { 187 swipego_wc_logger('IPN webhook failed'); 188 wp_die('Swipe IPN webhook failed', 'Swipe IPN', array('response' => 200)); 189 } 190 191 swipego_wc_logger('IPN webhook response: ' . wp_json_encode($response)); 192 193 if ($response['payment_link_reference_2'] !== 'woocommerce') { 194 return false; 195 } 196 197 $order_id = absint($response['payment_link_reference']); 198 $order = wc_get_order($order_id); 199 200 if (!$order) { 201 swipego_wc_logger('Order #' . $order_id . ' not found'); 178 202 return false; 179 203 } 180 204 181 205 // Check if it is correct payment link ID 182 if ( get_post_meta( $order_id, '_transaction_id', true ) !== $response['payment_link_id']) {206 if (get_post_meta($order_id, '_transaction_id', true) !== $response['payment_link_id']) { 183 207 return false; 184 208 } 185 209 186 210 // Check if the payment already marked as paid 187 if ( get_post_meta( $order_id, $response['payment_link_id'], true ) === 'paid') {211 if (get_post_meta($order_id, $response['payment_link_id'], true) === 'paid') { 188 212 return false; 189 213 } 190 214 191 215 try { 192 swipego_wc_logger( 'Verifying hash for order #' . $order_id);193 $this->swipego->validate_ipn_response( $response);194 } catch ( Exception $e) {195 swipego_wc_logger( $e->getMessage());196 wp_die( $e->getMessage(), 'Swipe IPN', array( 'response' => 200 ));216 swipego_wc_logger('Verifying hash for order #' . $order_id); 217 $this->swipego->validate_ipn_response($response); 218 } catch (Exception $e) { 219 swipego_wc_logger($e->getMessage()); 220 wp_die($e->getMessage(), 'Swipe IPN', array('response' => 200)); 197 221 } finally { 198 swipego_wc_logger( 'Verified hash for order #' . $order_id);199 } 200 201 if ( $response['payment_status'] == 1) {202 } 203 204 switch ( $response['payment_status']) {222 swipego_wc_logger('Verified hash for order #' . $order_id); 223 } 224 225 if ($response['payment_status'] == 1) { 226 } 227 228 switch ($response['payment_status']) { 205 229 case 1: 206 $this->handle_success_payment( $order, $response);230 $this->handle_success_payment($order, $response); 207 231 break; 208 232 209 233 case 2: 210 $this->handle_pending_payment( $order, $response);234 $this->handle_pending_payment($order, $response); 211 235 break; 212 236 213 237 default: 214 $this->handle_failed_payment( $order, $response);238 $this->handle_failed_payment($order, $response); 215 239 break; 216 240 } 217 241 218 swipego_wc_logger( 'IPN webhook success' ); 219 wp_die( 'Swipe IPN webhook success', 'Swipe IPN', array( 'response' => 200 ) ); 220 242 swipego_wc_logger('IPN webhook success'); 243 wp_die('Swipe IPN webhook success', 'Swipe IPN', array('response' => 200)); 221 244 } 222 245 223 246 // Handle success payment 224 private function handle_success_payment( WC_Order $order, $response ) { 225 226 update_post_meta( $order->get_id(), '_transaction_id', $response['payment_link_id'] ); 227 update_post_meta( $order->get_id(), $response['payment_link_id'], 'paid' ); 247 private function handle_success_payment(WC_Order $order, $response) 248 { 249 250 update_post_meta($order->get_id(), '_transaction_id', $response['payment_link_id']); 251 update_post_meta($order->get_id(), $response['payment_link_id'], 'paid'); 228 252 229 253 $order->payment_complete(); 230 254 231 $is_sandbox = swipego_wc_get_setting( 'environment' ) == 'sandbox'; 232 $sandbox_label = $is_sandbox ? __( 'Yes', 'swipego-wc' ) : __( 'No', 'swipego-wc' ); 233 234 $reference = '<br>.<br>' . esc_html__( 'Payment ID: ', 'swipego-wc' ) . $response['payment_link_id']; 235 $reference .= '<br>' . esc_html__( 'Sandbox: ', 'swipego-wc' ) . $sandbox_label; 236 237 if ( $response['payment_message'] ) { 238 $reference .= '<br>.<br>' . esc_html__( 'Other information: ', 'swipego-wc' ) . $response['payment_message']; 239 } 240 241 $order->add_order_note( esc_html__( 'Payment success!', 'swipego-wc' ) . $reference ); 242 243 swipego_wc_logger( 'Order #' . $order->get_id() . ' has been marked as Paid' ); 244 255 $is_sandbox = swipego_wc_get_setting('environment') == 'sandbox'; 256 $sandbox_label = $is_sandbox ? __('Yes', 'swipego-wc') : __('No', 'swipego-wc'); 257 258 $reference = '<br>.<br>' . esc_html__('Payment ID: ', 'swipego-wc') . $response['payment_link_id']; 259 $reference .= '<br>' . esc_html__('Sandbox: ', 'swipego-wc') . $sandbox_label; 260 261 if ($response['payment_message']) { 262 $reference .= '<br>.<br>' . esc_html__('Other information: ', 'swipego-wc') . $response['payment_message']; 263 } 264 265 $order->add_order_note(esc_html__('Payment success!', 'swipego-wc') . $reference); 266 267 swipego_wc_logger('Order #' . $order->get_id() . ' has been marked as Paid'); 245 268 } 246 269 247 270 // Handle pending payment 248 private function handle_pending_payment( WC_Order $order, $response ) {249 250 update_post_meta( $order->get_id(), '_transaction_id', $response['payment_link_id'] ); 251 update_post_meta( $order->get_id(), $response['payment_link_id'], 'pending');252 253 $order->update_status( 'wc-pending' ); 254 255 $is_sandbox = swipego_wc_get_setting( 'environment' ) == 'sandbox'; 256 $ sandbox_label = $is_sandbox ? __( 'Yes', 'swipego-wc' ) : __( 'No', 'swipego-wc' );257 258 $reference = '<br>.<br>' . esc_html__( 'Payment ID: ', 'swipego-wc' ) . $response['payment_link_id']; 259 $reference .= '<br>' . esc_html__( 'Sandbox: ', 'swipego-wc' ) . $sandbox_label;260 261 if ( $response['payment_message'] ) { 262 $reference .= '<br>.<br>' . esc_html__( 'Other information: ', 'swipego-wc' ) . $response['payment_message'];263 }264 265 $order->add_order_note( esc_html__( 'Payment pending!', 'swipego-wc' ) . $reference ); 266 267 swipego_wc_logger( 'Order #' . $order->get_id() . ' has been marked as Pending Payment' ); 268 271 private function handle_pending_payment(WC_Order $order, $response) 272 { 273 274 update_post_meta($order->get_id(), '_transaction_id', $response['payment_link_id']); 275 update_post_meta($order->get_id(), $response['payment_link_id'], 'pending'); 276 277 $order->update_status('wc-pending'); 278 279 $is_sandbox = swipego_wc_get_setting('environment') == 'sandbox'; 280 $sandbox_label = $is_sandbox ? __('Yes', 'swipego-wc') : __('No', 'swipego-wc'); 281 282 $reference = '<br>.<br>' . esc_html__('Payment ID: ', 'swipego-wc') . $response['payment_link_id']; 283 $reference .= '<br>' . esc_html__('Sandbox: ', 'swipego-wc') . $sandbox_label; 284 285 if ($response['payment_message']) { 286 $reference .= '<br>.<br>' . esc_html__('Other information: ', 'swipego-wc') . $response['payment_message']; 287 } 288 289 $order->add_order_note(esc_html__('Payment pending!', 'swipego-wc') . $reference); 290 291 swipego_wc_logger('Order #' . $order->get_id() . ' has been marked as Pending Payment'); 269 292 } 270 293 271 294 // Handle failed payment 272 private function handle_failed_payment( WC_Order $order, $response ) { 273 274 update_post_meta( $order->get_id(), '_transaction_id', $response['payment_link_id'] ); 275 update_post_meta( $order->get_id(), $response['payment_link_id'], 'failed' ); 276 277 $order->update_status( 'wc-failed' ); 278 279 $is_sandbox = swipego_wc_get_setting( 'environment' ) == 'sandbox'; 280 $sandbox_label = $is_sandbox ? __( 'Yes', 'swipego-wc' ) : __( 'No', 'swipego-wc' ); 281 282 $reference = '<br>.<br>' . esc_html__( 'Payment ID: ', 'swipego-wc' ) . $response['payment_link_id']; 283 $reference .= '<br>' . esc_html__( 'Sandbox: ', 'swipego-wc' ) . $sandbox_label; 284 285 if ( $response['payment_message'] ) { 286 $reference .= '<br>.<br>' . esc_html__( 'Other information: ', 'swipego-wc' ) . $response['payment_message']; 287 } 288 289 $order->add_order_note( esc_html__( 'Payment failed!', 'swipego-wc' ) . $reference ); 290 291 swipego_wc_logger( 'Order #' . $order->get_id() . ' has been marked as Failed' ); 292 293 } 294 295 private function handle_failed_payment(WC_Order $order, $response) 296 { 297 298 update_post_meta($order->get_id(), '_transaction_id', $response['payment_link_id']); 299 update_post_meta($order->get_id(), $response['payment_link_id'], 'failed'); 300 301 $order->update_status('wc-failed'); 302 303 $is_sandbox = swipego_wc_get_setting('environment') == 'sandbox'; 304 $sandbox_label = $is_sandbox ? __('Yes', 'swipego-wc') : __('No', 'swipego-wc'); 305 306 $reference = '<br>.<br>' . esc_html__('Payment ID: ', 'swipego-wc') . $response['payment_link_id']; 307 $reference .= '<br>' . esc_html__('Sandbox: ', 'swipego-wc') . $sandbox_label; 308 309 if ($response['payment_message']) { 310 $reference .= '<br>.<br>' . esc_html__('Other information: ', 'swipego-wc') . $response['payment_message']; 311 } 312 313 $order->add_order_note(esc_html__('Payment failed!', 'swipego-wc') . $reference); 314 315 swipego_wc_logger('Order #' . $order->get_id() . ' has been marked as Failed'); 316 } 295 317 } -
swipe-for-woocommerce/trunk/libraries/swipego/includes/abstracts/abstract-swipego-client.php
r2724990 r2737508 3 3 4 4 abstract class Swipego_Client { 5 6 5 7 6 const PRODUCTION_URL = 'https://api.swipego.io/api/';
Note: See TracChangeset
for help on using the changeset viewer.