Plugin Directory

Changeset 2737508


Ignore:
Timestamp:
06/05/2022 04:18:06 AM (4 years ago)
Author:
teamswipe
Message:

Update Plugin

Location:
swipe-for-woocommerce/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • swipe-for-woocommerce/trunk/README.md

    r2724952 r2737508  
    1 # f70-woocommerce
     1## Swipe for WooCommerce
     2Contributors: teamswipe
     3Tags: swipe, woocommerce, payment
     4Requires at least: 4.6
     5Tested up to: 5.9.2
     6Stable tag: 1.0.0
     7Requires PHP: 7.0
     8License: GPLv2 or later
     9License URI: https://www.gnu.org/licenses/gpl-2.0.html
    210
    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.
     11Accept credit card, online banking and e-wallet directly on your store with the Swipe payment gateway for WooCommerce.
    5612
    5713## 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.
    5914
    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
    6216
    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.
     17Accept credit card, online banking and e-wallet directly on your store with the Swipe payment gateway for WooCommerce.
     18
     19#### Credit Card
     20Visa 
     21MasterCard
     22
     23#### FPX Online Banking
     24Affin Bank 
     25AGRONet 
     26Alliance Bank 
     27AmBank 
     28Bank Islam 
     29Bank Muamalat 
     30Bank Rakyat 
     31BSN 
     32CIMB Clicks 
     33Hong Leong Bank 
     34HSBC Bank 
     35KFH 
     36Maybank2E 
     37Maybank2U 
     38OCBC Bank 
     39Public Bank 
     40RHB Bank 
     41Standard Chartered 
     42UOB Bank 
     43
     44#### e-Wallet
     45Coming Soon
     46
     47#### SWIPE INTRODUCTION
     48Swipe is a complete payment platform for businesses.
     49
     50We 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?
     53Swipe 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
     56Swipe 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
     59Swipe 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
     61The 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)
    6562
    6663## 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.
    6864
    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
    7166
    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.
     67Step for existing Swipe users:
     681. Install and activate your WooCommerce.
     692. Login your Swipe account.
     703. Choose your business.
     714. Start accepting payment.
    7472
    75 ## Roadmap
    76 If you have ideas for releases in the future, it is a good idea to list them in the README.
     73Step for new Swipe users:
     741. [Create your Swipe account](https://app.swipego.io/register).
     752. Add your business.
     763. Install and activate your WooCommerce.
     774. Login your Swipe account.
     785. Choose your business.
     796. Start accepting payment.
    7780
    78 ## Contributing
    79 State if you are open to contributions and what your requirements are for accepting them.
     81How to use WooCommerce plugin with Swipe:
     821. Install and activate your WooCommerce. 
     83Notes: You do not have to configure Swipe at WooCommerce, we have configured everything.
    8084
    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.
     85Video Tutorial > [Payment Integration for WooCommerce](https://www.youtube.com/watch?v=9mhcNP-xKWg) - Swipe
    8286
    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.
     87Explore us: [www.swipego.io](https://www.swipego.io)
    8488
    85 ## Authors and acknowledgment
    86 Show your appreciation to those who have contributed to the project.
     89Social Media: [Facebook](https://www.facebook.com/swipego/)
    8790
    88 ## License
    89 For open source projects, say how it is licensed.
     91## Changelog
    9092
    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  
    281281            $params = array(
    282282                'name'    => 'payment.created',
    283                 'url'     => WC()->api_request_url( get_class( $this ) ),
     283                'url'     => WC()->api_request_url( 'swipego_wc_gateway' ),
    284284                'enabled' => true,
    285285            );
  • swipe-for-woocommerce/trunk/includes/class-swipego-wc-gateway.php

    r2724952 r2737508  
    11<?php
    2 if ( !defined( 'ABSPATH' ) ) exit;
    3 
    4 class Swipego_WC_Gateway extends WC_Payment_Gateway {
     2if (!defined('ABSPATH')) exit;
     3
     4class Swipego_WC_Gateway extends WC_Payment_Gateway
     5{
    56
    67    private $swipego;
     
    1213    private $debug;
    1314
    14     public function __construct() {
     15    public function __construct()
     16    {
    1517
    1618        $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');
    2426        $this->icon               = SWIPEGO_URL . 'assets/images/logo-swipe.svg';
    2527
    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;
    3133
    3234        $this->register_hooks();
    3335
    3436        // Check if the payment gateway is ready to use
    35         if ( !$this->validate_required_settings() ) {
     37        if (!$this->validate_required_settings()) {
    3638            $this->enabled = 'no';
    3739        }
    3840
    3941        $this->init_api();
    40 
    4142    }
    4243
    4344    // 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
    4971
    5072    // Check if all required settings is filled
    51     private function validate_required_settings() {
     73    private function validate_required_settings()
     74    {
    5275        return $this->api_key
    5376            && $this->signature_key
     
    5679
    5780    // Initialize API
    58     private function init_api() {
     81    private function init_api()
     82    {
    5983        $this->swipego = new Swipego_WC_API();
    6084    }
    6185
    6286    // 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)) {
    7095            return false;
    7196        }
     
    7398        try {
    7499            // 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)) {
    78103                    return array(
    79104                        'result'   => 'success',
     
    83108            }
    84109
    85             swipego_wc_logger( 'Creating payment for order #' . $order_id );
     110            swipego_wc_logger('Creating payment for order #' . $order_id);
    86111
    87112            $params = array(
     
    90115                'amount'       => (float) $order->get_total(),
    91116                '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),
    95120                'reference'    => $order->get_id(),
    96121                'reference_2'  => 'woocommerce',
     
    98123            );
    99124
    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]);
    107132                }
    108133            }
    109134
    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']));
    114139            }
    115140
    116141            // Redirect to the payment page
    117             if ( isset( $response['data']['payment_url'] ) ) {
     142            if (isset($response['data']['payment_url'])) {
    118143                return array(
    119144                    'result'   => 'success',
     
    121146                );
    122147            }
    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');
    126150        }
    127151
    128152        return;
    129 
    130153    }
    131154
    132155    // 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    {
    134158
    135159        try {
    136160
    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]);
    144168                }
    145169            }
    146170
    147             if ( isset( $response['data']['payment_url'] ) ) {
     171            if (isset($response['data']['payment_url'])) {
    148172                return $response['data']['payment_url'];
    149173            }
    150 
    151         } catch ( Exception $e ) {}
     174        } catch (Exception $e) {
     175        }
    152176
    153177        return false;
    154 
    155178    }
    156179
    157180    // Handle IPN
    158     public function handle_ipn() {
     181    public function handle_ipn()
     182    {
    159183
    160184        $response = $this->swipego->get_ipn_response();
    161185
    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');
    178202            return false;
    179203        }
    180204
    181205        // 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']) {
    183207            return false;
    184208        }
    185209
    186210        // 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') {
    188212            return false;
    189213        }
    190214
    191215        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));
    197221        } 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']) {
    205229            case 1:
    206                 $this->handle_success_payment( $order, $response );
     230                $this->handle_success_payment($order, $response);
    207231                break;
    208232
    209233            case 2:
    210                 $this->handle_pending_payment( $order, $response );
     234                $this->handle_pending_payment($order, $response);
    211235                break;
    212236
    213237            default:
    214                 $this->handle_failed_payment( $order, $response );
     238                $this->handle_failed_payment($order, $response);
    215239                break;
    216240        }
    217241
    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));
    221244    }
    222245
    223246    // 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');
    228252
    229253        $order->payment_complete();
    230254
    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');
    245268    }
    246269
    247270    // 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');
    269292    }
    270293
    271294    // 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    }
    295317}
  • swipe-for-woocommerce/trunk/libraries/swipego/includes/abstracts/abstract-swipego-client.php

    r2724990 r2737508  
    33
    44abstract class Swipego_Client {
    5 
    65
    76    const PRODUCTION_URL = 'https://api.swipego.io/api/';
Note: See TracChangeset for help on using the changeset viewer.