From 08ac5b0cd19f7b7060b3c9d5f09fd2cea26d338c Mon Sep 17 00:00:00 2001 From: Craig Christenson Date: Thu, 19 Jan 2023 13:53:04 -0500 Subject: [PATCH] Support new 2Checkout interfaces. --- README.md | 43 +- commerce_2checkout/LICENSE.txt | 339 -------- commerce_2checkout/commerce_2checkout.api.php | 37 - commerce_2checkout/commerce_2checkout.info | 13 - commerce_2checkout/commerce_2checkout.module | 464 ----------- .../commerce_2checkout.rules.inc | 37 - commerce_2checkout/images/2checkout.gif | Bin 1225 -> 0 bytes commerce_2checkout/images/amex.gif | Bin 645 -> 0 bytes commerce_2checkout/images/discover.gif | Bin 495 -> 0 bytes commerce_2checkout/images/mastercard.gif | Bin 808 -> 0 bytes commerce_2checkout/images/paypal.gif | Bin 520 -> 0 bytes commerce_2checkout/images/visa.gif | Bin 335 -> 0 bytes commerce_tco2payjs.zip | Bin 0 -> 16954 bytes .../commerce_tco2payjs.info.yml | 12 + .../commerce_tco2payjs.libraries.yml | 8 + .../commerce_tco2payjs.routing.yml | 15 + .../commerce_tco2payjs.services.yml | 4 + .../schema/commerce_tco2payjs.schema.yml | 19 + commerce_tco2payjs/js/twocheckout.js | 92 +++ .../src/Controller/Response3ds.php | 124 +++ .../Commerce/PaymentGateway/Tco2Payjs.php | 739 ++++++++++++++++++ .../PaymentGateway/Tco2PayjsInterface.php | 19 + .../PaymentMethodType/Tco2PayJsType.php | 37 + .../Onsite/PaymentMethodAddForm.php | 64 ++ .../src/Twocheckout/ApiHelper.php | 158 ++++ commerce_tco_convert_plus.zip | Bin 0 -> 8827 bytes .../commerce_tco_convert_plus.info.yml | 11 + commerce_tco_convert_plus/composer.json | 10 + .../commerce_tco_convert_plus.schema.yml | 18 + .../PaymentGateway/TcoConvertPlusRedirect.php | 288 +++++++ .../TcoCpRedirect/TcoConvertPlusForm.php | 169 ++++ commerce_tco_inline.zip | Bin 0 -> 10671 bytes .../commerce_tco_inline.info.yml | 11 + .../commerce_tco_inline.libraries.yml | 8 + commerce_tco_inline/composer.json | 10 + .../schema/commerce_tco_inline.schema.yml | 21 + commerce_tco_inline/js/commerce_tco_inline.js | 46 ++ .../PaymentGateway/TcoInlineRedirect.php | 244 ++++++ .../TcoInlineRedirect/TcoInlineForm.php | 123 +++ .../src/Twocheckout/ApiHelper.php | 179 +++++ 40 files changed, 2442 insertions(+), 920 deletions(-) delete mode 100644 commerce_2checkout/LICENSE.txt delete mode 100644 commerce_2checkout/commerce_2checkout.api.php delete mode 100644 commerce_2checkout/commerce_2checkout.info delete mode 100644 commerce_2checkout/commerce_2checkout.module delete mode 100644 commerce_2checkout/commerce_2checkout.rules.inc delete mode 100644 commerce_2checkout/images/2checkout.gif delete mode 100644 commerce_2checkout/images/amex.gif delete mode 100644 commerce_2checkout/images/discover.gif delete mode 100644 commerce_2checkout/images/mastercard.gif delete mode 100644 commerce_2checkout/images/paypal.gif delete mode 100644 commerce_2checkout/images/visa.gif create mode 100644 commerce_tco2payjs.zip create mode 100644 commerce_tco2payjs/commerce_tco2payjs.info.yml create mode 100644 commerce_tco2payjs/commerce_tco2payjs.libraries.yml create mode 100644 commerce_tco2payjs/commerce_tco2payjs.routing.yml create mode 100644 commerce_tco2payjs/commerce_tco2payjs.services.yml create mode 100644 commerce_tco2payjs/config/schema/commerce_tco2payjs.schema.yml create mode 100644 commerce_tco2payjs/js/twocheckout.js create mode 100644 commerce_tco2payjs/src/Controller/Response3ds.php create mode 100644 commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2Payjs.php create mode 100644 commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2PayjsInterface.php create mode 100644 commerce_tco2payjs/src/Plugin/Commerce/PaymentMethodType/Tco2PayJsType.php create mode 100644 commerce_tco2payjs/src/PluginForm/Onsite/PaymentMethodAddForm.php create mode 100644 commerce_tco2payjs/src/Twocheckout/ApiHelper.php create mode 100644 commerce_tco_convert_plus.zip create mode 100644 commerce_tco_convert_plus/commerce_tco_convert_plus.info.yml create mode 100644 commerce_tco_convert_plus/composer.json create mode 100644 commerce_tco_convert_plus/config/schema/commerce_tco_convert_plus.schema.yml create mode 100644 commerce_tco_convert_plus/src/Plugin/Commerce/PaymentGateway/TcoConvertPlusRedirect.php create mode 100644 commerce_tco_convert_plus/src/PluginForm/TcoCpRedirect/TcoConvertPlusForm.php create mode 100644 commerce_tco_inline.zip create mode 100644 commerce_tco_inline/commerce_tco_inline.info.yml create mode 100644 commerce_tco_inline/commerce_tco_inline.libraries.yml create mode 100644 commerce_tco_inline/composer.json create mode 100644 commerce_tco_inline/config/schema/commerce_tco_inline.schema.yml create mode 100644 commerce_tco_inline/js/commerce_tco_inline.js create mode 100644 commerce_tco_inline/src/Plugin/Commerce/PaymentGateway/TcoInlineRedirect.php create mode 100644 commerce_tco_inline/src/PluginForm/TcoInlineRedirect/TcoInlineForm.php create mode 100644 commerce_tco_inline/src/Twocheckout/ApiHelper.php diff --git a/README.md b/README.md index 16ac86d..b980fe5 100644 --- a/README.md +++ b/README.md @@ -5,35 +5,18 @@ How to integrate Drupal Commerce with 2Checkout ### Commerce Settings: -1. Download or clone https://github.com/craigchristenson/drupal-commerce-2checkout.git -2. Upload the **commerce_2checkout** directory to your modules directory. -3. Sign in to your Drupal admin -4. Under **Store** click **Configure Store**. -5. Click **Payment Methods** -6. Click **2checkout** and add action "Enable payment method: 2checkout" -7. Under **Account Number** enter your 2Checkout account number. -8. Under Secret Word enter your **Secret Word** (Must be the same value set on 2Checkout site management page.) -9. Select your checkout page language. -10. Select **Demo** to place demo sales or do not select for live sales. (If you are testing on a demo account, make sure you have your Site URL setup in your 2Checkout application. The return process will not complete if the domain your are testing on does not match the domain regestered to your 2Checkout account.) -11. Select **One Page Checkout** to use your custom single page checkout. -12. Select Third Party Cart to use third party cart parameters. Unselect to use Pass Through Products (Lists lineitem prices at 2Checkout). -13. Select **Log notifications during processing**. -14. Click **Save**. - -### 2Checkout Settings: - -1. Sign in to your 2Checkout account -2. Click the **Account** tab and **Site Management** subcategory. -3. Under **Direct Return** select **Header Redirect**. -4. Under **Secret Word** enter your Secret Word (Must be the same value entered in your Drupal Commerce admin.) -5. Click **Save Changes**. - -NOTE: If you use the sandbox mode, take into account that you won't be -redirected back to your site because the `x_receipt_link_url` parameter -only works on live accounts: - -- http://help.2checkout.com/articles/FAQ/Can-I-specify-the-return-URL-on-the-fly/ +1. Download or clone https://github.com/2checkout/drupal-commerce-2checkout.git +2. Sign in to your Drupal admin +3. Install the included extension archive for the 2Checkout interface that you want to use. +4. Under **Commerce** click **Configuration**. +5. Click **Payment Gateways** +6. Click **Add Payment Gateway**. +7. Enter a **Name** and select the 2Checkout Plugin that you installed. +8. Enter the **Merchant Code** found in your 2Checkout panel Integrations section. +9. Enter the **Secret Key** found in your 2Checkout panel Integrations section. +10. Enter the **Buy Link Secret Word** found in your 2Checkout panel Integrations section. +11. Select **Test** or **Live** mode. +12. Select **Enabled** under Status. +13. Click **Save**. **Please contact 2Checkout directly with any integration questions.** - -_Fork of original project at http://drupal.org/project/commerce_2checkout_ diff --git a/commerce_2checkout/LICENSE.txt b/commerce_2checkout/LICENSE.txt deleted file mode 100644 index d159169..0000000 --- a/commerce_2checkout/LICENSE.txt +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/commerce_2checkout/commerce_2checkout.api.php b/commerce_2checkout/commerce_2checkout.api.php deleted file mode 100644 index 3ce39b3..0000000 --- a/commerce_2checkout/commerce_2checkout.api.php +++ /dev/null @@ -1,37 +0,0 @@ -commerce_line_items[LANGUAGE_NONE] as $li) { - $data['li_' . $i . '_price'] = number_format((float) $data['li_' . $i . '_price'] / $USD_BOB, 2, '.', ''); - $i++; - } -} - -/** - * Implements hook_commerce_2checkout_validate_form_data_alter(). - */ -function hook_commerce_2checkout_validate_form_data_alter(&$data, $order) { - $USD_BOB = (float) variable_get('currency_usd_2_bob', 6.97); - - $data['total'] = number_format((float) $data['total'] * $USD_BOB, 2, '.', ''); -} diff --git a/commerce_2checkout/commerce_2checkout.info b/commerce_2checkout/commerce_2checkout.info deleted file mode 100644 index 01da435..0000000 --- a/commerce_2checkout/commerce_2checkout.info +++ /dev/null @@ -1,13 +0,0 @@ -name = Commerce 2CheckOut -description = Payment using 2checkout -package = Commerce (contrib) -dependencies[] = commerce_payment -dependencies[] = rules -core = 7.x - -; Information added by drupal.org packaging script on 2012-03-03 -version = "7.x-1.x-dev" -core = "7.x" -project = "commerce_2checkout" -datestamp = "1330776422" - diff --git a/commerce_2checkout/commerce_2checkout.module b/commerce_2checkout/commerce_2checkout.module deleted file mode 100644 index fa2ed2e..0000000 --- a/commerce_2checkout/commerce_2checkout.module +++ /dev/null @@ -1,464 +0,0 @@ - $icons['2checkout'])); - unset ($icons['2checkout']); - $display_title .= '
' . t('Includes:') . '' . implode(' ', $icons) . '
'; - - $payment_methods['2checkout'] = array( - 'base' => 'commerce_2checkout', - 'title' => t('2checkout'), - 'short_title' => t('2checkout'), - 'display_title' => $display_title, - 'description' => t('2checkout'), - 'terminal' => FALSE, - 'offsite' => TRUE, - 'offsite_autoredirect' => TRUE, - ); - - return $payment_methods; -} - - -/** - * Payment method callback: settings form. - */ -function commerce_2checkout_settings_form($settings = NULL) { - $form = array(); - - $settings = (array) $settings + array( - 'business' => '', - 'secret_word' => '', - 'demo' => false, - 'sandbox' => false, - 'fixed' => true, - 'language' => 'en', - 'pay_method' => 'CC', - 'skip_landing' => true, - 'direct_checkout' => true, - 'third_party_cart' => true, - 'tangible' => true, - 'logging' => '', - 'coupon' => '', - ); - - $form['business'] = array( - '#type' => 'textfield', - '#title' => t('Account number'), - '#description' => t('Your 2checkout account number.'), - '#default_value' => $settings['business'], - '#maxlength' => 64, - '#required' => TRUE, - ); - $form['secret_word'] = array( - '#type' => 'textfield', - '#title' => t('Secret Word'), - '#description' => t('2Checkout Secret Word
Must be the same value you have entered in your 2Checkout Site Management Page.'), - '#default_value' => $settings['secret_word'], - '#maxlength' => 64, - '#required' => TRUE, - ); - $form['skip_landing'] = array( - '#type' => 'checkbox', - '#title' => t('Skip landing.'), - '#description' => t('skip the order review page of the multi-page purchase routine.'), - '#default_value' => $settings['skip_landing'], - ); - $form['language'] = array( - '#type' => 'select', - '#title' => t('Checkout page language.'), - '#options' => commerce_2checkout_languages(), - '#default_value' => $settings['language'], - ); - $form['demo'] = array( - '#type' => 'checkbox', - '#title' => t('Demo mode.'), - '#description' => t('Enable demo mode.'), - '#default_value' => $settings['demo'], - ); - $form['sandbox'] = array( - '#type' => 'checkbox', - '#title' => t('Sandbox.'), - '#description' => t('Use sandbox site (https://sandbox.2checkout.com/).'), - '#default_value' => $settings['sandbox'], - ); - $form['direct_checkout'] = array( - '#type' => 'checkbox', - '#title' => t('Inline Checkout.'), - '#description' => t('If disabled, customer will go to standard checkout.'), - '#default_value' => $settings['direct_checkout'], - ); - $form['third_party_cart'] = array( - '#type' => 'checkbox', - '#title' => t('Third Party Cart.'), - '#description' => t('Select to use third party cart parameters. Do not select to use Pass Through Products (Lists lineitem prices at 2Checkout)'), - '#default_value' => $settings['third_party_cart'], - ); - $form['tangible'] = array( - '#type' => 'checkbox', - '#title' => t('Tangible goods.'), - '#description' => t('Set to Yes to send shipping address to 2Checkout.'), - '#default_value' => $settings['tangible'], - ); - $form['logging'] = array( - '#type' => 'radios', - '#title' => t('Logging'), - '#options' => array( - 'notification' => t('Log notifications during processing.'), - 'full' => t('Log notifications with all data during validation and processing (used for debugging).'), - ), - '#default_value' => $settings['logging'], - ); - - return $form; -} - - -/** - * Payment method callback: adds a message and CSS to the submission form. - */ -function commerce_2checkout_submit_form($payment_method, $pane_values, $checkout_pane, $order) { - $form['2checkout_information'] = array( - '#markup' => '' . t('(Continue with checkout to complete payment via 2checkout.)') . '', - ); - - return $form; -} - - -/** - * Payment method callback: redirect form, a wrapper around the module's general - * use function for building a 2checkout form. - */ -function commerce_2checkout_redirect_form($form, &$form_state, $order, $payment_method) { - // Return an error if the enabling action's settings haven't been configured. - if (empty($payment_method['settings']['business'])) { - drupal_set_message(t('2checkout is not configured for use. No 2checkout account id has been specified.'), 'error'); - return array(); - } - - return commerce_2checkout_order_form($form, $form_state, $order, $payment_method['settings']); -} - - -/** - * Payment method callback: all returns from 2checkout are returned here. - */ -function commerce_2checkout_redirect_form_validate($order, $payment_method) { - - if (!empty($payment_method['settings']['logging']) && - $payment_method['settings']['logging'] == 'full') { - watchdog('commerce_2checkout', 'Customer returned from 2checkout with the following POST data:
' . check_plain(print_r($_REQUEST, TRUE)) . '
', array(), WATCHDOG_NOTICE); - } - - global $user; - $seller_id = $payment_method['settings']['business']; - $secret_word = $payment_method['settings']['secret_word']; - $order_number = $_REQUEST['order_number']; - - if ($payment_method['settings']['demo'] == '1') { - $order_number = 1; - } - - $compare_string = $secret_word . $seller_id . $order_number . $_REQUEST['total']; - $compare_hash1 = strtoupper(md5($compare_string)); - $compare_hash2 = $_REQUEST['key']; - - if ($compare_hash1 != $compare_hash2) { - return FALSE; - } else { - $settings = $payment_method['settings']; - commerce_order_status_update($order, 'completed'); - commerce_order_save ($order); - // Save the transaction information. - - // Allow modules to alter parameters of the API response. - drupal_alter('commerce_2checkout_validate_form_data', $_REQUEST, $order); - - $transaction = commerce_payment_transaction_new('2checkout', $_REQUEST['merchant_order_id']); - $transaction->instance_id = $payment_method['instance_id']; - $transaction->amount = commerce_currency_decimal_to_amount($_REQUEST['total'], commerce_default_currency()); - $transaction->currency_code = commerce_default_currency(); - $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS; - $transaction->message = t('The payment has completed.'); - commerce_payment_transaction_save($transaction); - } -} - - -/** - * Helper function to get some country code; requires Apache's mod_geoip to - * be loaded and enabled. - */ -function commerce_2checkout_guess_country_code () { - if (isset($_REQUEST['country_code'])) { - return $_REQUEST['country_code']; - } else if (function_exists('apache_note')) { - return apache_note('GEOIP_COUNTRY_CODE'); - } else { - return false; - } -} - - -/** - * Keyed array of 2checkout parameters - */ -function commerce_2checkout_purchase_parameters ($order, $settings) { - $wrapper = entity_metadata_wrapper('commerce_order', $order); - $currency_code = $wrapper->commerce_order_total->currency_code->value(); - $amount = $wrapper->commerce_order_total->amount->value(); - - if (isset ($order->commerce_customer_billing[LANGUAGE_NONE][0])) { - $billing_address = $wrapper->commerce_customer_billing->commerce_customer_address->value(); - $profile_id = $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id']; - $profile = commerce_customer_profile_load ($profile_id); - } - if (isset ($order->commerce_customer_shipping[LANGUAGE_NONE][0])) - $shipping_address = $wrapper->commerce_customer_shipping->commerce_customer_address->value(); - // Build the data array that will be translated into hidden form values. - $data = array ( - // 2Checkout account number - 'sid' => $settings['business'], - - // Set language code - 'lang' => $settings['language'], - - 'merchant_order_id' => $order->order_id, - - // CC for Credit Card, PPI for PayPal. This will set the default selection on the payment method step during the checkout process. - 'pay_method' => 'CC', - - // If set to 1 it will skip the order review page of the multi-page checkout. - 'skip_landing' => $settings['skip_landing'], - - // Used to specify an approved URL on-the-fly, but is limited to the same domain that is used for your 2Checkout account, otherwise it will fail. This parameter will over-ride any URL set on the Site Management page. - 'x_receipt_link_url' => url('checkout/' . $order->order_id . '/payment/return/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)), - - // Specify a 2Checkout created coupon code. If applicable, the coupon will - // be automatically applied to the sale. - 'coupon' => '', - - // Populate the billing information page - 'card_holder_name' => isset ($billing_address) ? $billing_address['name_line']: '', - 'city' => isset ($billing_address) ? $billing_address['locality']: '', - 'country' => isset ($billing_address) ? $billing_address['country'] : commerce_2checkout_guess_country_code(), - 'state' => isset ($billing_address) ? $billing_address['administrative_area'] : 'XX', - 'zip' => isset ($billing_address) ? $billing_address['postal_code']: '', - 'street_address' => isset ($billing_address) ? $billing_address['thoroughfare']: '', - 'street_address2' => isset ($billing_address) ? $billing_address['premise']: '', - 'email' => $order->mail, - - // Commerce has no phone field, so just try something. It's required for - // 2checkout, so try to pass something in is better than having the user - // fill in more details on another form. - 'phone' => isset ($profile->field_phone[LANGUAGE_NONE][0]['value']) ? $profile->field_phone[LANGUAGE_NONE][0]['value'] : '', - ); - - //Populate the shipping address - if (isset($shipping_address)) { - $data['ship_name'] = isset ($shipping_address) ? $shipping_address['name_line']: ''; - $data['ship_city'] = isset ($shipping_address) ? $shipping_address['locality']: ''; - $data['ship_country'] = isset ($shipping_address) ? $shipping_address['country'] : commerce_2checkout_guess_country_code(); - $data['ship_state'] = isset ($shipping_address) ? $shipping_address['administrative_area'] : 'XX'; - $data['ship_zip'] = isset ($shipping_address) ? $shipping_address['postal_code']: ''; - $data['ship_street_address'] = isset ($shipping_address) ? $shipping_address['thoroughfare']: ''; - $data['ship_street_address2'] = isset ($shipping_address) ? $shipping_address['premise']: ''; - } - - if ($settings['third_party_cart']) { - $data['cart_order_id'] = $order->order_id; - $data['total'] = number_format($amount, 2, '.', '')/100; - $i = 0; - foreach ($order->commerce_line_items[LANGUAGE_NONE] as $li) { - $line_item_id = $li['line_item_id']; - $line_item = commerce_line_item_load ($line_item_id); - if ($line_item->type == 'product') { - $product_id = ($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']); - $product = commerce_product_load ($product_id); - } - $data['c_prod_' . $i] = $product_id.','.intval($line_item->quantity); - $data['c_name_' . $i] = $product->title; - $data['c_description_' . $i] = $product->sku; - $data['c_price_' . $i] = round (commerce_currency_amount_to_decimal($line_item->commerce_unit_price[LANGUAGE_NONE][0]['amount'], $line_item->commerce_total[LANGUAGE_NONE][0]['currency_code']), 2); - $i++; - } - - } - else { - // Emit a line for every product - $data['mode'] = '2CO'; - $i = 0; - foreach ($order->commerce_line_items[LANGUAGE_NONE] as $li) { - $line_item_id = $li['line_item_id']; - $line_item = commerce_line_item_load ($line_item_id); - if ($line_item->type == 'product') { - $product_id = intval ($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']); - $product = commerce_product_load ($product_id); - $name = $product->title; - $data['li_' . $i . '_type'] = $line_item->type; - } - elseif ($line_item->type == 'shipping') { - $name = $line_item->data['shipping_service']['display_title']; - $data['li_' . $i . '_type'] = 'product'; - } - else { - $name = 'unknown item'; - $data['li_' . $i . '_type'] = $line_item->type; - } - $data['li_' . $i . '_name'] = $name; - $data['li_' . $i . '_quantity'] = intval ($line_item->quantity); - $data['li_' . $i . '_price'] = round (commerce_currency_amount_to_decimal($line_item->commerce_unit_price[LANGUAGE_NONE][0]['amount'], $line_item->commerce_total[LANGUAGE_NONE][0]['currency_code']), 2); - $data['li_' . $i . '_tangible'] = 'N'; - $i++; - } - } - - $data['currency_code'] = $currency_code; - - // Y to enable demo mode. Do not pass this in for live sales. - if ($settings['demo'] == 1) - $data['demo'] = 'Y'; - - // Allow modules to alter parameters of the API request. - drupal_alter('commerce_2checkout_order_form_data', $data, $order); - - return $data; -} - - -/** - * Builds a 2checkout form from an order object. - * - * @param $order - * The fully loaded order being paid for. - * @param $settings - * An array of settings used to build out the form, including: - * - account: the 2checkout account the payment submits to - * - x_receipt_link_url: the URL 2checkout should send the user to on successful payment - * - language: the language code to use on the payment form - * - * @return - * A renderable form array. - */ -function commerce_2checkout_order_form($form, &$form_state, $order, $settings) { - $data = commerce_2checkout_purchase_parameters ($order, $settings); - - $form['#action'] = commerce_2checkout_server_url($settings); - - foreach ($data as $name => $value) { - if (!empty($value)) { - $form[$name] = array('#type' => 'hidden', '#value' => $value); - } - } - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Proceed to 2checkout'), - ); - - if ($settings['direct_checkout'] == 1) { - echo ''; - } - - return $form; -} - - -/** - * Redirects to checkouts using GET instead of form POST - */ -function commerce_2checkout_redirect_checkout ($order) { - // Generate a key to use in the return URL from the redirected service. - $order->data['payment_redirect_key'] = drupal_hash_base64(time()); - // And force 2checkout payment mechanism, must supply a payment instance id - reset ($order->payment_methods); - $order->data['payment_method'] = key ($order->payment_methods); - $order->data['offsite'] = true; - commerce_order_save($order); - - // And make proper URL - $settings = reset ($order->payment_methods); - $settings = $settings['settings']; - $data = commerce_2checkout_purchase_parameters ($order, $settings); - drupal_goto (commerce_2checkout_server_url ($settings), array ('query' => $data)); -} - - -/** - * Assume the shipping rate is available in $_REQUEST, and add that - * now. Useful when product + shipping rates are on one page. - */ -function commerce_2checkout_add_shipping ($order) { - if (isset ($_REQUEST['shipping_service'])) { - $service = $_REQUEST['shipping_service']; - $shipping_service = commerce_shipping_service_load($service); - $callback = commerce_shipping_service_callback($shipping_service, 'rate'); - $price = $callback($shipping_service, $order); - $line_item = commerce_shipping_service_rate_calculate($service, $price, $order->order_id); - commerce_shipping_add_shipping_line_item ($line_item, $order); - } -} - - -/** - * Returns an array of 2checkout payment method icon img elements. - * - * @return - * The array of themed payment method icons keyed by name: visa, mastercard, - * amex, discover, paypal, 2checkout - */ -function commerce_2checkout_icons() { - $icons = array(); - - $payment_methods = array( - 'visa' => t('Visa'), - 'mastercard' => t('Mastercard'), - 'amex' => t('American Express'), - 'discover' => t('Discover'), - 'paypal' => t('PayPal'), - '2checkout' => t('2checkout'), - ); - - foreach ($payment_methods as $name => $title) { - $path = url(drupal_get_path('module', 'commerce_2checkout') . '/images/' . $name . '.gif', array('absolute' => TRUE)); - $icons[$name] = '' . $title . ''; - } - - return $icons; -} - - -/** - * Returns the URL to the specified 2checkout server. - * - * @return - * The URL to use to submit requests to 2checkout. - */ -function commerce_2checkout_server_url ($settings) { - return $settings['sandbox'] ? 'https://sandbox.2checkout.com/checkout/purchase' : 'https://www.2checkout.com/checkout/purchase'; -} - - -/** - * Returns an array of all possible language codes. - */ -function commerce_2checkout_languages() { - return array('en' => 'English', 'zh' => 'Chinese', 'da' => 'Danish', 'nl' => 'Dujtch', 'fr' => 'French', 'gr' => 'German', 'el' => 'Greek', 'it' => 'Italian', 'jp' => 'Japanese', 'no' => 'Norwegian', 'pt' => 'Portugese', 'sl' => 'Slovenian', 'es_ib' => 'Spanish (es_ib)', 'es_la' => 'Spanish (es_la)', 'sv' => 'Swedish'); -} - - -/** - * Returns an array of all possible currency codes. - */ -function commerce_2checkout_currencies() { - return drupal_map_assoc(array('AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'MYR', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD')); -} diff --git a/commerce_2checkout/commerce_2checkout.rules.inc b/commerce_2checkout/commerce_2checkout.rules.inc deleted file mode 100644 index a9b63ed..0000000 --- a/commerce_2checkout/commerce_2checkout.rules.inc +++ /dev/null @@ -1,37 +0,0 @@ - t('Redirect to 2checkout'), - 'parameter' => array( - 'commerce_order' => array( - 'type' => 'commerce_order', - 'label' => t('Order in checkout'), - ), - ), - 'group' => t('Commerce Checkout'), - 'base' => 'commerce_2checkout_redirect_checkout', - ); - $actions['commerce_2checkout_add_shipping'] = array( - 'label' => t('Add shipping rates from $_REQUEST'), - 'parameter' => array( - 'commerce_order' => array( - 'type' => 'commerce_order', - 'label' => t('Order in checkout'), - ), - ), - 'group' => t('Commerce Shipping'), - 'base' => 'commerce_2checkout_add_shipping', - ); - return $actions; -} diff --git a/commerce_2checkout/images/2checkout.gif b/commerce_2checkout/images/2checkout.gif deleted file mode 100644 index aef5dc9e733b369b7bc5bb7ed2a154af2f5e2fc6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1225 zcmeIx-A_|@90u^;uRTXgTS{R?tJFwiK~RQuqO@b0)7IHmG^tt))2R^HMAR)tW7I%$ zFo*=i;Gz+=LMx#7!srkxn^F&N()XUzQp!pzEh2j1g%`^b6QZ8}72f#dljr)IZ}O`_~-~e172Q4%kxG@fH*uYI2xJ9$WTXqJ`U}qZah{28;9O!MwqT3D@t<}M9 zb#Pjp>^3K-&B<+ZCK{bQqch3m;+tH_CRYmWj_aE^x8RODmF{+TYP)+$yL)N7TiD@Q z*5O&+=}GJKh~m7WyPg$s-t>FkRb8Z{i_ExBX5Ob(KOk2>pt2uQYaUW-<9s=fe7Ur4 z-@0zUwA;77+rR!#{{~u*Kd;BXv1eiv&Fs%NPsq#xxjFFtUx9+&z~dYed7Ev;P;z%tgaj3##j*cJUv0QcVT2DT^GA@s=)L_fS za*3Q=%ul870HG8A9W7+!gVJTtb{H~IfI&S<*r0Up0{4ibq&629E=Z&Zc`^1+VP%xr zrGnYG^qmE=Uc47~Ce-pP1_=aH^6%AN8bov}nin&K+OlhaSMx0|2jiC}rf2d5@1?3} zqA~XuXbSB@WC9cl1}KulCt~CYw92SVScyxOh`5LxN>ZF^9y+pp0*rD_gW1}$S55i5 zHTxswH?_IktHXPAgXK7=Wj$d09&m9iN+>|!u9(8H>K8Hw&NCiyL-3W0+h{es@4Ag|2B=r>-PI&wci9@ovEBX{Xc=c)Dw_*Cc(v4sNwJp49a8^!E4oVVud{>hdU{)8X&;0DizkjlrS8 z-v9sqA^8LW002J#EC2ui03`qw000L6z~ApcD7ucV;vw=GKy(yJqrs~pt{#Clz!eIK z#-wuDgsh@dD>l3BdNbhSnCv`DscLq+5D-n1P6n#092c4w20ffC54EAOG!n2mk~E&u>is z$dF;6ih;$DRV+4E0S4vDm|?gI@C!#DEmsoh!KA4)gVU(Fp#B`XwW86aGi_+g#|!8+ fxM9auy#d3F+CpyY9-gUqan{7!C^ybrNDu%!L`@`- diff --git a/commerce_2checkout/images/discover.gif b/commerce_2checkout/images/discover.gif deleted file mode 100644 index 29ad882356adbb73b9560c9ba04dc15cb53bc4ea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 495 zcmVPx^0tNdzmxjdzW@9A_xJb4#l`!}sN&+{z`wutk3#a{)AfltH#If$^YiWP z?f?J(A^8LW002J#EC2ui03`qw000L6z~3)GEE#PR9cZ6nG*}&4JegHz$YBS_T9Q1O`0@3+4a|TI5s&2L}@iH7Xdw3?C^~ z6y#B1H-Uza2=5}?n81Nbh!FzMR3WiJfPjb+qlBnv@glB_Q5qx|(Xk^&GZie9TzPU! lg$_AZ%4{h`q)M4MJ$}(b!bXP-oIovlQbM%ok{>|;06W>9?qC1_ diff --git a/commerce_2checkout/images/mastercard.gif b/commerce_2checkout/images/mastercard.gif deleted file mode 100644 index a2313881a1b8cbe5989a96f71beee4698ac4fd12..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 808 zcmZ?wbhEHbRAmrlc$UWS{==7lT6`1Jts~w1|Az=f%J^Pjm6{-IeyBzD1C!v#1(FAk zUj1JuffpYA>{f90bzHqHy`7x{b zKYRXzTaRAYeDMF}&VQo3|4-!HpEU2^xr-Mg<^H{U|L@(Uf1e*V$2t6;Cvsu&rY2FF zi@l2XnZ*u*%vS@_@2_x}&a{!`#P7^Qr0 z{j7iWt^c@r9~_+YZ~o$gZZYYS?*HyRSX}G<@A206Pp|!ZdE|kG#Ct=#HRXm|IaUA1 z3qClu;Qv1V_xlSjoV&1T_1XtLG82p}FQ`~PsL@)(r}O^8)e9|?4=&yIV4Cdz&4%wE zoY=H%-u#6QC^dsiB4*mNjaYTklHI|VrRosls=e3(n{_>TTPXU^DZUN|Imr8g=5 z#$E-UXNGqU=_hS}uswRN;d4faxgpv^LT4dsf{L}r1O)|FMsAh~kv)xTSmk{T z*&obha_sNi8^QD`RJfQ|j=lKyn@o<{$V*0NQ?hEp64q>8Qhr0ohx1r&li|e&3b7U+ vc1;)MNK(>hT;|Zw>ak5(G@|f<17p}kogATtqyy>?nngP0_n+`lV6X-Ns<=sx diff --git a/commerce_2checkout/images/paypal.gif b/commerce_2checkout/images/paypal.gif deleted file mode 100644 index aad82f03ed1376445c3004b93a2831527b2f48a1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 520 zcmZ?wbhEHbRAmrnxT??a|LvKdD4oMCB z_itA4DmG4=e*fD3^_$l`yK}6dW%8$|Ck5qClRyg_1(pjdO1#!` z3A8(GW_nSz|G|bE(I?pi9&fSgQQ*2(u(d&AeYbPT?t8P@EyTFx3Rzo{S%ricYI&G@ z#bvT2SSGXRB&hL9$%<9VF!ONtuyHL>5>#N2;}Vo+kx*sfl;_+eq{}NL$y&+JEY2^? zEGQ^)kc*j5oS9#Yg_V;cEJk6u1y7Bi6sh67ApOjqyioWOoy_Vl`59-Ryq#slo>akG5AHY{S~Y?G6z zsr>Muf4=_&1(6?2jLlvgDn>Og7qcBaWs`Grj9njY;VfwI czGRrX#h~`n74Hu1$Qc?pPl7Kpd z--WK0xd#{-8UN4Y|Ns9#mvsY>WFQ(S{$ycfU=U=`0qFqQ$-sIhLBupAb6!SOR}!;9 zfzJ7ovkbh}Mgi~tA6Ou8=)^{;JqwFGO}0%s^J4u9XRr0PuRb1pTeUxifq|#2Z%>;; z{+VD0wx;-ph6;UqpRrZsHfUVQa$#cR_vA_qO~_-&s}(2|U}WKE$*=2(j?c5yEJtc*;_~f!sZoZ3` zE?>ENjgPzX!u30MZ```~@aoO;kDl>yK5^&Ze*5nIhmW7QIV!cj|IijxWUvMR3qpd6 diff --git a/commerce_tco2payjs.zip b/commerce_tco2pay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ej&*h22J&zzifPU{K__@3%F{b@J(6i2f=a_GBzRx6gsU%>4jn6)XSlwm*qH zcaz^MbbreFNx$Te-5>vXq5mKFv5@w8z3y`!GcHNU5|3^qR{>i06tRBtdLBN0uj>8D z<4Nc4|7#w<)c8Ip)hqjh)Hfs)lqYh__GIBBl>dX6zNf05WB!bqKiye){P*zudqV6vCfw_P zg88rX*mLOni;gh_&Kba;4*iqLb5;DFMEeQ-cpse@`*|r1YeL0h+&+#`A>3b5PPNlZ>Y$?@tvtFg=f`KlbI{(-J>HpXBiJ@$CIK pf$cfyFG-5$4Em>jF!*`hb^FNx1oUxw0QAQn9cTc6HpZvB{|CAdV^jbD literal 0 HcmV?d00001 diff --git a/commerce_tco2payjs/commerce_tco2payjs.info.yml b/commerce_tco2payjs/commerce_tco2payjs.info.yml new file mode 100644 index 0000000..fd620e8 --- /dev/null +++ b/commerce_tco2payjs/commerce_tco2payjs.info.yml @@ -0,0 +1,12 @@ +name: 2Checkout 2PayJs Gateway by Verifone +type: module +description: 'Provides payment using 2Checkout 2PayJs OnSite' +package: Verifone Payment Gateways +core_version_requirement: ^8.7.8 || ^9 +dependencies: + - commerce:commerce + - commerce:commerce_payment + +# Information added by Drupal.org packaging script on 2021-06-30 +version: '8.x-1.00' +project: 'commerce_tco2payjs' \ No newline at end of file diff --git a/commerce_tco2payjs/commerce_tco2payjs.libraries.yml b/commerce_tco2payjs/commerce_tco2payjs.libraries.yml new file mode 100644 index 0000000..e987cf2 --- /dev/null +++ b/commerce_tco2payjs/commerce_tco2payjs.libraries.yml @@ -0,0 +1,8 @@ +twocheckout: + js: + js/twocheckout.js: { } + dependencies: + - core/jquery + - core/drupal + - core/jquery.once + \ No newline at end of file diff --git a/commerce_tco2payjs/commerce_tco2payjs.routing.yml b/commerce_tco2payjs/commerce_tco2payjs.routing.yml new file mode 100644 index 0000000..00347bc --- /dev/null +++ b/commerce_tco2payjs/commerce_tco2payjs.routing.yml @@ -0,0 +1,15 @@ +commerce_tco2payjs.success3ds: + path: '/commerce_tco2payjs/success3ds' + defaults: + _controller: '\Drupal\commerce_tco2payjs\Controller\Response3ds::success' + _title: '3DS Successful validation' + requirements: + _access: 'TRUE' + +commerce_tco2payjs.failed3ds: + path: '/commerce_tco2payjs/cancel3ds' + defaults: + _controller: '\Drupal\commerce_tco2payjs\Controller\Response3ds::cancel' + _title: '3DS Failed validation' + requirements: + _access: 'TRUE' diff --git a/commerce_tco2payjs/commerce_tco2payjs.services.yml b/commerce_tco2payjs/commerce_tco2payjs.services.yml new file mode 100644 index 0000000..a7a543e --- /dev/null +++ b/commerce_tco2payjs/commerce_tco2payjs.services.yml @@ -0,0 +1,4 @@ +services: + tco2Payjs: + class: Drupal\commerce_tco2payjs\Plugin\Commerce\PaymentGateway\Tco2Payjs + arguments: ['@request_stack'] \ No newline at end of file diff --git a/commerce_tco2payjs/config/schema/commerce_tco2payjs.schema.yml b/commerce_tco2payjs/config/schema/commerce_tco2payjs.schema.yml new file mode 100644 index 0000000..328682a --- /dev/null +++ b/commerce_tco2payjs/config/schema/commerce_tco2payjs.schema.yml @@ -0,0 +1,19 @@ +commerce_tco2payjs.commerce_payment_gateway.plugin.tcop2payjs_onsite: + type: commerce_payment_gateway_configuration + mapping: + ptcomcode: + type: string + label: 'Merchant Code' + ptcomsecretkey: + type: string + label: 'Secret Key' + ptcomsecretword: + type: string + label: 'Buy Link secret Word' + ptcousedefaultstyle: + type: text + label: 'Payment Form Style' + # the mode + ptcotest: + type: string + label: 'Mode' \ No newline at end of file diff --git a/commerce_tco2payjs/js/twocheckout.js b/commerce_tco2payjs/js/twocheckout.js new file mode 100644 index 0000000..c04662a --- /dev/null +++ b/commerce_tco2payjs/js/twocheckout.js @@ -0,0 +1,92 @@ +/** + * @file + * Twocheckout 2payjs javascript funcitonality. + */ + +(function commerce_tco2payjs_gateway_form($, Drupal, drupalSettings) { +'use strict'; + +$.fn.hasAttr = function(name) { + return this.attr(name) !== undefined; + }; + +//Use this to form the fullname for token. +//Sometimes the address data can be new or allready save. +//Either way the class is the same + +function getClassValue(identifier){ + let str = drupalSettings.tokenName.formBillN; + let el = $(identifier) + if(el.hasAttr('value')){ + str = el.val(); + } + else{ + str = el.html(); + } + return str; +} + +var script = document.createElement('script'); +script.onload = function() { +$(document).ready(function () { + Drupal.behaviors.tco2payjsForm = { + attach: function (context, drupalSettings) { + + $('#tco2payjs-form', context).once('tco2payjs-processed').each(function () { + + if (!drupalSettings.tco2payjs.merchantid) { + console.log('Merchant id is missing!'); + return; + } + + let jsPaymentClient = new TwoPayClient(drupalSettings.tco2payjs.merchantid); + let form = $('#tco2payjs-form', context).closest('form'); + let component = jsPaymentClient.components.create('card', drupalSettings.tco2payjs.paymentFormStyle); + component.mount("#tco2payjs-form"); + + form.on('submit.handle2payjsSubmit', function (e) { + e.preventDefault(); + // Prevents double click + form.find(":input.button--primary").prop("disabled", true); + + let fn = getClassValue('.given-name'); + let sn = getClassValue('.family-name'); + + var billingDetails = {name: fn+' '+sn}; + + jsPaymentClient.tokens.generate(component, billingDetails).then(function (response) { + Drupal.behaviors.tco2payjsForm.tco2PayJsSuccessResponseHandler(form, response.token); + }).catch(function (error) { + Drupal.behaviors.tco2payjsForm.tco2PayJsErrorResponseHandler(form, error.message); + }); + return false; + }); + + form.find(':input.button--primary').prop('disabled', false); + }); + }, + detach: function (context, drupalSettings) { + let form = $('#tco2payjs-form', context).closest('form'); + form.off('submit.handle2payjsSubmit'); + }, + tco2PayJsSuccessResponseHandler: function (form, token) { + //Add token_id in the form + form.find('#verifoneTokenId').val(token); + form.get(0).submit(); //Submit + }, + + tco2PayJsErrorResponseHandler: function (form, msg) { + console.log('2payJs Error: '+msg); + form.find(":input.button--primary").prop("disabled", false); + }, + }; + + //reload behaviours. This is important! + Drupal.attachBehaviors(); +}); + +}; +script.src = "https://2pay-js.2checkout.com/v1/2pay.js"; +document.getElementsByTagName('head')[0].appendChild(script); + +}(jQuery, Drupal, drupalSettings)); diff --git a/commerce_tco2payjs/src/Controller/Response3ds.php b/commerce_tco2payjs/src/Controller/Response3ds.php new file mode 100644 index 0000000..987a899 --- /dev/null +++ b/commerce_tco2payjs/src/Controller/Response3ds.php @@ -0,0 +1,124 @@ +requestStack = $request_stack; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) + { + return new static( + $container->get('request_stack') + ); + } + + /** + * @throws \Exception + */ + public function success() + { + $orderId = $this->requestStack->getCurrentRequest()->query->get('commerce_order', null); + $transactionId = $this->requestStack->getCurrentRequest()->query->get('REFNO', null); + $gatewayId = $this->requestStack->getCurrentRequest()->query->get('gatewayId', null); + + if (!isset($$orderId) && !isset($gatewayId) && !isset($transactionId)) { + throw new PaymentGatewayException("Missing correct parameters! Cannot finish payment processing."); + } + + $gateway = PaymentGateway::load($gatewayId); + $configs = $gateway->getPlugin()->getConfiguration(); + $tcoApi = new ApiHelper($configs); + + $redirectTo = null; + + try { + + if ($transactionId) { + $response = $tcoApi->getOrder($transactionId); + if (isset($response['RefNo'])) { + $payment_state = ($response['Status'] == "COMPLETE" || $response['Status'] == "AUTHRECEIVED") ? 'completed' : 'authorization'; + //Load payments and update based on transactionId (aka RefNo) + $payments = \Drupal::entityQuery('commerce_payment') + ->condition('remote_id', trim($response['RefNo'])) + ->execute(); + foreach ($payments as $value) { + $payment = Payment::load($value); + $payment->setState($payment_state); + $payment->save(); + } + + \Drupal::messenger()->addMessage( + $this->t('Your payment was successful with Order id : @orderid and Transaction id : @transaction_id', + ['@orderid' => $order->id(), '@transaction_id' => $response['RefNo']])); + $redirectTo = '/checkout/' . $orderId . '/complete'; + } else { + throw new Exception('Invalid reference order!'); + } + } + } catch (\Exception $e) { + \Drupal::logger('commerce_tco2payjs')->critical($e->getMessage()); + + \Drupal::messenger()->addMessage( + $this->t('Something went wrong when validating 3ds response. Orrder number: @orderid and Transaction id : @transaction_id', + ['@orderid' => $orderId, '@transaction_id' => $transactionId]),MessengerInterface::TYPE_ERROR); + $redirectTo = $redirectTo = '/checkout/' . $orderId . '/complete'; + } + + $gateway->getPlugin()->goTo($redirectTo); + } + + public function cancel() + { + $orderId = $this->requestStack->getCurrentRequest()->query->get('commerce_order'); + $transactionId = $this->requestStack->getCurrentRequest()->query->get('REFNO'); + $gatewayId = $this->requestStack->getCurrentRequest()->query->get('gatewayId', null); + \Drupal::logger('commerce_tco2payjs')->info('Payment failed because of unsuccessful 3ds validation!'); + + \Drupal::messenger()->addMessage( + $this->t('Something went wrong when validating 3ds response. Orrder number: @orderid and Transaction id : @transaction_id', + ['@orderid' => $orderId, '@transaction_id' => $transactionId]),MessengerInterface::TYPE_ERROR); + $redirectTo = $redirectTo = '/checkout/' . $orderId . '/complete'; + + $gateway = PaymentGateway::load($gatewayId); + $gateway->getPlugin()->goTo($redirectTo); + } + +} diff --git a/commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2Payjs.php b/commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2Payjs.php new file mode 100644 index 0000000..3975687 --- /dev/null +++ b/commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2Payjs.php @@ -0,0 +1,739 @@ + '', + 'ptcomsecretkey' => '', + 'ptcomsecretword' => '', + 'ptcousedefaultstyle' => 'true', + 'ptcotest' => 'test', + ] + parent::defaultConfiguration(); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) + { + $form = parent::buildConfigurationForm($form, $form_state); + + $ptcomcode = isset($this->configuration['ptcomcode']) ? $this->configuration['ptcomcode'] : ''; + $ptcomsecretkey = isset($this->configuration['ptcomsecretkey']) ? $this->configuration['ptcomsecretkey'] : ''; + $ptcomsecretword = isset($this->configuration['ptcomsecretword']) ? $this->configuration['ptcomsecretword'] : ''; + $ptcomstyle = isset($this->configuration['ptcostyle']) ? $this->configuration['ptcostyle'] : $this->getDefaultStyle(); + $ptcousedefaultstyle = isset($this->configuration['ptcousedefaultstyle']) ? $this->configuration['ptcousedefaultstyle'] : 'true'; + + + $form['ptcomcode'] = [ + '#type' => 'textfield', + '#title' => $this->t('Merchant Code'), + '#default_value' => $ptcomcode, + '#description' => $this->t('Use Merchant Code field value from 2Checkout by Verifone Cpanel'), + '#required' => true, + ]; + $form['ptcomsecretkey'] = [ + '#type' => 'textfield', + '#title' => $this->t('Secret Key'), + '#default_value' => $ptcomsecretkey, + '#description' => $this->t('Secret Key from Cpanel'), + '#required' => true, + ]; + $form['ptcomsecretword'] = [ + '#type' => 'textfield', + '#title' => $this->t('Buy Link secret Word'), + '#default_value' => $ptcomsecretword, + '#description' => $this->t('Buy Link secret Word from Cpanel'), + '#required' => false, + ]; + $form['ptcousedefaultstyle'] = [ + '#type' => 'radios', + '#title' => $this->t('Use Payament Form default style '), + '#default_value' => $ptcousedefaultstyle, + '#options' => ['true' => 'Yes', 'false' => 'No'], + '#description' => $this->t('Revert back to default form style'), + '#required' => false, + ]; + $form['ptcostyle'] = [ + '#type' => 'textarea', + '#title' => $this->t('Payment Form Style'), + '#default_value' => $ptcomstyle, + '#description' => $this->t('Payment Form Style CSS'), + '#required' => false, + ]; + $form['ptcotest'] = [ + '#type' => 'hidden', + '#title' => $this->t('Mode'), + '#default_value' => $this->getMode(), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) + { + parent::submitConfigurationForm($form, $form_state); + + if (!$form_state->getErrors()) { + $values = $form_state->getValue($form['#parents']); + + $this->configuration['ptcomcode'] = $values['ptcomcode']; + $this->configuration['ptcomsecretkey'] = $values['ptcomsecretkey']; + $this->configuration['ptcomsecretword'] = $values['ptcomsecretword']; + $this->configuration['ptcostyle'] = $values['ptcostyle']; + $this->configuration['ptcousedefaultstyle'] = $values['ptcousedefaultstyle']; + $this->configuration['ptcotest'] = $this->getMode(); + } + } + + /** + * default style for API form + * + * @return string + */ + public function getDefaultStyle() + { + return '{ + "margin": "0", + "fontFamily": "Helvetica, sans-serif", + "fontSize": "1rem", + "fontWeight": "400", + "lineHeight": "1.5", + "color": "#212529", + "textAlign": "left", + "backgroundColor": "#FFFFFF", + "*": { + "boxSizing": "border-box" + }, + ".no-gutters": { + "marginRight": 0, + "marginLeft": 0 + }, + ".row": { + "display": "flex", + "flexWrap": "wrap" + }, + ".col": { + "flexBasis": "0", + "flexGrow": "1", + "maxWidth": "100%", + "padding": "0", + "position": "relative", + "width": "100%" + }, + "div": { + "display": "block" + }, + ".field-container": { + "paddingBottom": "14px" + }, + ".field-wrapper": { + "paddingRight": "25px" + }, + ".input-wrapper": { + "position": "relative" + }, + "label": { + "display": "inline-block", + "marginBottom": "9px", + "color": "#313131", + "fontSize": "14px", + "fontWeight": "300", + "lineHeight": "17px" + }, + "input": { + "overflow": "visible", + "margin": 0, + "fontFamily": "inherit", + "display": "block", + "width": "100%", + "height": "42px", + "padding": "10px 12px", + "fontSize": "18px", + "fontWeight": "400", + "lineHeight": "22px", + "color": "#313131", + "backgroundColor": "#FFF", + "backgroundClip": "padding-box", + "border": "1px solid #CBCBCB", + "borderRadius": "3px", + "transition": "border-color .15s ease-in-out,box-shadow .15s ease-in-out", + "outline": 0 + }, + "input:focus": { + "border": "1px solid #5D5D5D", + "backgroundColor": "#FFFDF2" + }, + ".is-error input": { + "border": "1px solid #D9534F" + }, + ".is-error input:focus": { + "backgroundColor": "#D9534F0B" + }, + ".is-valid input": { + "border": "1px solid #1BB43F" + }, + ".is-valid input:focus": { + "backgroundColor": "#1BB43F0B" + }, + ".validation-message": { + "color": "#D9534F", + "fontSize": "10px", + "fontStyle": "italic", + "marginTop": "6px", + "marginBottom": "-5px", + "display": "block", + "lineHeight": "1" + }, + ".card-expiration-date": { + "paddingRight": ".5rem" + }, + ".is-empty input": { + "color": "#EBEBEB" + }, + ".lock-icon": { + "top": "calc(50% - 7px)", + "right": "10px" + }, + ".valid-icon": { + "top": "calc(50% - 8px)", + "right": "-25px" + }, + ".error-icon": { + "top": "calc(50% - 8px)", + "right": "-25px" + }, + ".card-icon": { + "top": "calc(50% - 10px)", + "left": "10px", + "display": "none" + }, + ".is-empty .card-icon": { + "display": "block" + }, + ".is-focused .card-icon": { + "display": "none" + }, + ".card-type-icon": { + "right": "30px", + "display": "block" + }, + ".card-type-icon.visa": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.mastercard": { + "top": "calc(50% - 14.5px)" + }, + ".card-type-icon.amex": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.discover": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.jcb": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.dankort": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.cartebleue": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.diners": { + "top": "calc(50% - 14px)" + }, + ".card-type-icon.elo": { + "top": "calc(50% - 14px)" + } + }'; + } + + /** + * {@inheritdoc} + * @throws \Exception + */ + public function createPayment(PaymentInterface $payment, $capture = true) + { + //1. Validate payment + $payment_method = null; + try { + $this->assertPaymentState($payment, ['new']); + $payment_method = $payment->getPaymentMethod(); + $this->assertPaymentMethod($payment_method); + } catch (\InvalidArgumentException $e) { + \Drupal::logger('commerce_tco2payjs')->critical($e->getMessage()); + throw new HardDeclineException($this->t("There was an error while trying to perform the payment. No charge was made.")); + } + + //2. Get Order + //Identify Order + $order = $payment->getOrder(); + $order_id = $payment->getOrderId(); + + + //3. Billing data + // Note: Since requires_billing_information is FALSE, the payment method + // is not guaranteed to have a billing profile. Confirm tha + // $payment_method->getBillingProfile() is not NULL before trying to use it. + $billing = $lang = null; + + if ($billing_profile = $payment_method->getBillingProfile()) { + /** @var \Drupal\address\Plugin\Field\FieldType\AddressItem $billing_address */ + $address = $billing_profile->get('address')->first(); + $lang = $address->getLocale(); + $billing = [ + 'Address1' => $address->getAddressLine1() ?? '', + 'City' => $address->getLocality(), + 'State' => $address->getAdministrativeArea(), + 'CountryCode' => $address->getCountryCode(), + 'Email' => $order->getEmail(), + 'FirstName' => $address->getGivenName(), + 'LastName' => $address->getFamilyName(), + 'Zip' => $address->getPostalCode() ?? '', + 'Company' => $address->getOrganization() ?? '', + ]; + if ($address->getAddressLine2()) { + $billing['Address2'] = $address->getAddressLine2(); + } + if (property_exists($billing_profile, 'field_phone')) { + $billing['Phone'] = $billing_profile->get('field_phone')->value; + } + } else { + //3.b. Get Billing data from Shippment Data + $shipments = $order->get('shipments'); + $shipping = null; + foreach ($shipments as $shipment) { + /** @var \Drupal\commerce_shipping\Entity\Shipment $shipment */ + $shipment = $shipment->entity; + $address = $shipment->getShippingProfile()->get('address')->first(); + $lang = $address->getLocale(); + $shipping[] = [ + 'Address1' => $address->getAddressLine1() ?? '', + 'City' => $address->getLocality(), + 'State' => $address->getAdministrativeArea(), + 'CountryCode' => $address->getCountryCode(), + 'Email' => $order->getEmail(), + 'FirstName' => $address->getGivenName(), + 'LastName' => $address->getFamilyName(), + 'Zip' => $address->getPostalCode() ?? '', + 'Company' => $address->getOrganization() ?? '', + ]; + if ($address->getAddressLine2()) { + $shipping[]['Address2'] = $address->getAddressLine2(); + } + if (property_exists($shipment->getShippingProfile(), 'field_phone')) { + $shipping[]['Phone'] = $shipment->getShippingProfile()->get('field_phone')->value; + } + } + $billing = $shipping[0]; + } + + //4. Check if language has been determined + if ($lang === 'und') { + $lang = \Drupal::languageManager()->getCurrentLanguage()->getId(); + } + + //5. Get token + $token = $payment_method->getRemoteId(); + + //6. Determine products + $products[] = [ + 'Name' => 'Cart_' . $order_id, + 'Description' => 'Drupal Products Order', + 'Quantity' => 1, + 'IsDynamic' => true, + 'Tangible' => false, + 'PurchaseType' => 'PRODUCT', + 'Price' => + [ + 'Amount' => round($payment->getAmount()->getNumber(), 2), + 'Type' => 'CUSTOM', + ], + ]; + + $mode = $this->configuration['ptcotest']; + + $order_3ds_params = [ + 'currency' => $payment->getAmount()->getCurrencyCode(), + 'order_id' => $order_id, + 'test' => $mode == "test" ? 1 : 0, + 'token' => $token, + 'gatewayId' => $payment_method->getPaymentGatewayId(), + ]; + + //7. Assemble parameters for request + $dynamicProductParams = [ + 'Country' => $billing['CountryCode'], + 'Currency' => $payment->getAmount()->getCurrencyCode(), + 'CustomerIP' => \Drupal::request()->getClientIp(), + 'ExternalReference' => $order_id, + 'Language' => $lang, + 'Source' => 'DRUPAL_' . str_replace(".", '_', \Drupal::VERSION), + 'BillingDetails' => $billing, + 'Items' => $products, + 'PaymentDetails' => $this->getPaymentDetailsWith3DsUrls($order_3ds_params), + ]; + + //8. Do Api request + $tcoApi = new ApiHelper($this->configuration); + + try { + $apiResponse = $tcoApi->call($dynamicProductParams); + if (isset($apiResponse['error_code'])) { + \Drupal::logger('commerce_tco2payjs')->critical(sprintf('2Checkout api call errors: %s - %s', $apiResponse['error_code'], $apiResponse['message'])); + \Drupal::messenger()->addMessage($apiResponse['message'], MessengerInterface::TYPE_ERROR); + throw new \Exception('2Checkout api call error!'); + } + } catch (\Exception $e) { + \Drupal::messenger()->addMessage($this->t($e->getMessage()), MessengerInterface::TYPE_ERROR); + throw new \Exception($e->getMessage()); + }; + $redirectTo = $hasAuthorize3ds = null; + + if (isset($apiResponse['RefNo'])) { + + //Save payment in pending state. + $payment->setState('pending'); + $payment->setAuthorizedTime($this->time->getRequestTime()); + $payment->setRemoteId($apiResponse['RefNo']); + + //Do another request to check the final state before continuing. + $response = $tcoApi->getOrder($apiResponse['RefNo']); + if (isset($response['RefNo'])) { + if (isset($response['PaymentDetails']['PaymentMethod']['Authorize3DS'])) { + $hasAuthorize3ds = $this->hasAuthorize3DS($response['PaymentDetails']['PaymentMethod']['Authorize3DS']); + } else { + $payment_state = ($response['Status'] == "COMPLETE" || $response['Status'] == "AUTHRECEIVED") ? 'completed' : 'authorization'; + $payment->setState($payment_state); + } + $redirectTo = $hasAuthorize3ds ? $hasAuthorize3ds : $redirectTo; + } + $payment->save(); + } + if ($redirectTo) { + $this->goTo($redirectTo); + } else { + + \Drupal::messenger()->addMessage( + $this->t('Your payment was successful with Order id : @orderid and Transaction id : @transaction_id', + ['@orderid' => $order->id(), '@transaction_id' => $apiResponse['RefNo']])); + } + } + + public function hasAuthorize3DS($has3ds) + { + if (isset($has3ds) && isset($has3ds['Href']) && !empty($has3ds['Href'])) { + + return $has3ds['Href'] . '?avng8apitoken=' . $has3ds['Params']['avng8apitoken']; + } + + return null; + } + + public function getPaymentDetailsWith3DsUrls($params_array) + { + + return [ + 'Type' => $params_array['test'] ? 'TEST' : 'EES_TOKEN_PAYMENT', + "Currency" => $params_array["currency"], + 'PaymentMethod' => [ + 'EesToken' => $params_array['token'], + 'Vendor3DSReturnURL' => $this->get3DsCallbackUrl([ + 'action' => 'success', + 'orderId' => $params_array['order_id'], + 'gatewayId' => $params_array['gatewayId'], + ]), + 'Vendor3DSCancelURL' => $this->get3DsCallbackUrl([ + 'action' => 'cancel', + 'orderId' => $params_array['order_id'], + 'gatewayId' => $params_array['gatewayId'], + ]), + ], + ]; + } + + /** + * Generates urls for success after 3ds redirect && for failure/cancel + * Use unix timestamp fort cart id for the sake of example + */ + public function get3DsCallbackUrl($params) + { + $url = ''; + if (isset($params['action']) && $params['action'] == "success") { + $url = Url::FromRoute('commerce_tco2payjs.success3ds', + [ + 'commerce_order' => $params['orderId'], + 'gatewayId' => $params['gatewayId'], + ], + ['absolute' => true]) + ->toString(); + } + + if (isset($params['action']) && $params['action'] == "cancel") { + $url = Url::FromRoute('commerce_tco2payjs.failed3ds', + [ + 'commerce_order' => $params['orderId'], + 'gatewayId' => $params['gatewayId'], + ], + ['absolute' => true]) + ->toString(); + } + + return $url; + } + + /** + * {@inheritdoc} + */ + public function capturePayment(PaymentInterface $payment, Price $amount = null) + { + $this->assertPaymentState($payment, ['authorization']); + // If not specified, capture the entire amount. + $amount = $amount ?: $payment->getAmount(); + + // Perform the capture request here, throw an exception if it fails. + // See \Drupal\commerce_payment\Exception for the available exceptions. + $remote_id = $payment->getRemoteId(); + $number = $amount->getNumber(); + + $payment->setState('completed'); + $payment->setAmount($amount); + $payment->save(); + } + + /** + * {@inheritdoc} + */ + public function voidPayment(PaymentInterface $payment) + { + \Drupal::logger('commerce_tco2payjs')->info('Void payment not implemented for 2payjs'); + } + + + /** + * {@inheritdoc} + */ + public function createPaymentMethod(PaymentMethodInterface $payment_method, array $payment_details) + { + if (empty($payment_details['verifoneTokenId'])) { + // if the js file is not loaded in time, we will hit this issue - so we redirect it back + \Drupal::messenger()->addMessage( + $this->t('To use 2Checkout 2PayJs by Verifone payment method, please wait for the credit card form to be loaded!'), + MessengerInterface::TYPE_WARNING); + header("Location: " . $_SERVER['HTTP_REFERER']); + exit(); + } + $token = $payment_details['verifoneTokenId']; + + //This is just for drupal to not throw error. + $payment_method->card_type = 'visa'; + $payment_method->setRemoteId($token); + $payment_method->setReusable(false); + $payment_method->save(); + } + + /** + * {@inheritdoc} + */ + public function deletePaymentMethod(PaymentMethodInterface $payment_method) + { + // Delete the remote record here, throw an exception if it fails. + // See \Drupal\commerce_payment\Exception for the available exceptions. + // Delete the local entity. + $payment_method->delete(); + } + + /** + * {@inheritdoc} + */ + public function buildAvsResponseCodeLabel($avs_response_code, $card_type) + { + if ($card_type == 'dinersclub' || $card_type == 'jcb') { + if ($avs_response_code == 'A') { + return $this->t('Approved.'); + } + return null; + } + return parent::buildAvsResponseCodeLabel($avs_response_code, $card_type); + } + + public function getMerchantId() + { + return $this->configuration['ptcomcode']; + } + + public function getSecretKey() + { + return $this->configuration['ptcomsecretkey']; + } + + public function getConfiguration() + { + return $this->configuration; + } + + public function goTo($path) + { + $response = new RedirectResponse($path); + $response->send(); + return; + } + + + public function refundPayment(PaymentInterface $payment, Price $amount = null) + { + + if (!$this->canRefundPayment($payment)) { + \Drupal::messenger()->addMessage($this->t('Order cannot be refunded!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException('Order cannot be refunded!'); + } + + $this->assertPaymentState($payment, ['completed', 'partially_refunded']); + // If not specified, refund the entire amount. + $amount = $amount ?: $payment->getAmount(); + $this->assertRefundAmount($payment, $amount); + + try { + $remote_id = $payment->getRemoteId(); + $decimal_amount = $amount->getNumber(); + $api = new ApiHelper($this->configuration); + + $order = $api->getOrder($remote_id); + if (!$order) { + \Drupal::messenger()->addMessage($this->t('Invalid transaction ID!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException("Invalid transaction ID"); + } + + if ($amount->getCurrencyCode() !== strtoupper($order['PaymentDetails']['Currency'])) { + \Drupal::messenger()->addMessage($this->t('Cannot refund order in different currencies!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException($this->t('Cannot refund order in different currencies!')); + } + + if ($decimal_amount > $order['GrossPrice']) { + \Drupal::messenger()->addMessage($this->t('You cannot refund more than order total'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException($this->t('You cannot refund more than order total')); + } + + $this->refund($decimal_amount, $order, $api); + } catch (\Exception $e) { + + throw new PaymentGatewayException($e->getMessage()); + } + + // Determine whether payment has been fully or partially refunded. + $old_refunded_amount = $payment->getRefundedAmount(); + $new_refunded_amount = $old_refunded_amount->add($amount); + if ($new_refunded_amount->lessThan($payment->getAmount())) { + $payment->setState('partially_refunded'); + } else { + $payment->setState('refunded'); + } + \Drupal::messenger()->addMessage( + $this->t('@amount @currency refunded with success!', + [ + '@amount' => $decimal_amount, + '@currency' => $amount->getCurrencyCode(), + ])); + $payment->setRefundedAmount($new_refunded_amount); + $payment->save(); + } + + /** + * @throws \Exception + */ + private function refund($amount, $order, $api) + { + + $params = [ + "amount" => $order['GrossPrice'], + "comment" => 'Request by merchant', + "reason" => 'Other', + 'items' => [ + [ + 'Quantity' => 1, + 'LineItemReference' => $order["Items"][0]['LineItemReference'], + 'Amount' => $amount, + ], + ], + ]; + + $response = $api->refund($order['RefNo'], $params); + if (isset($response['error_code']) && !empty($response['error_code'])) { + \Drupal::messenger()->addMessage($this->t('Refund failed. Reason: @message', ['@message' => $response['message']]), + MessengerInterface::TYPE_ERROR); + throw new \Exception('Refund failed. Reason: ' . $response['message']); + } + } + +} diff --git a/commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2PayjsInterface.php b/commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2PayjsInterface.php new file mode 100644 index 0000000..2cf7fbe --- /dev/null +++ b/commerce_tco2payjs/src/Plugin/Commerce/PaymentGateway/Tco2PayjsInterface.php @@ -0,0 +1,19 @@ +t('Twocheckout 2PayJs Payment (by Verifone)'); + } + + /** + * {@inheritdoc} + */ + public function buildFieldDefinitions() { + $fields = parent::buildFieldDefinitions(); + + return $fields; + } + +} diff --git a/commerce_tco2payjs/src/PluginForm/Onsite/PaymentMethodAddForm.php b/commerce_tco2payjs/src/PluginForm/Onsite/PaymentMethodAddForm.php new file mode 100644 index 0000000..7f78f74 --- /dev/null +++ b/commerce_tco2payjs/src/PluginForm/Onsite/PaymentMethodAddForm.php @@ -0,0 +1,64 @@ +entity; + if ($payment_method->bundle() === '2payjs_type') { + $form['payment_details'] = $this->build2PayJsForm($form['payment_details'], $form_state); + } + return $form; + } + + /** + * {@inheritdoc} + */ + public function build2PayJsForm(array $element, FormStateInterface $form_state) + { + /** @var \Drupal\commerce_braintree\Plugin\Commerce\PaymentGateway\HostedFieldsInterface $plugin */ + $gatewayConfiguration = $this->plugin->getConfiguration(); + $element['#attributes']['class'][] = 'tco2payjs-form'; + + $element['verifoneTokenId'] = [ + '#type' => 'hidden', + '#attributes' => ['id' => 'verifoneTokenId'], + ]; + $element['#attributes']['id'][] = 'tco2payjs-form'; + $element['#attached']['library'][] = 'commerce_tco2payjs/twocheckout'; + + $element['#attached']['drupalSettings']['tco2payjs'] = [ + 'merchantid' => $this->plugin->getMerchantId(), + 'paymentFormStyle' => json_decode($gatewayConfiguration['ptcousedefaultstyle'] === 'true' ? $this->plugin->getDefaultStyle() : $gatewayConfiguration['ptcostyle']), + ]; + $element['#attached']['drupalSettings']['tokenName'] = ['formBillN' => 'John Doe']; + $element['number']['#default_value'] = ''; + return $element; + } + + /** + * {@inheritdoc} + */ + protected function validateCreditCardForm(array &$element, FormStateInterface $form_state) + { + if (!isset($form_state->getValues()['payment_information']['add_payment_method']['payment_details']['verifoneTokenId'])) { + $form_state->setErrorByName('verifoneTokenId', "An error ocurred while processing your credit card."); + } + } + + /** + * {@inheritdoc} + */ + public function submitCreditCardForm(array $element, FormStateInterface $form_state) + { + + } + +} diff --git a/commerce_tco2payjs/src/Twocheckout/ApiHelper.php b/commerce_tco2payjs/src/Twocheckout/ApiHelper.php new file mode 100644 index 0000000..6971def --- /dev/null +++ b/commerce_tco2payjs/src/Twocheckout/ApiHelper.php @@ -0,0 +1,158 @@ +sellerId = $configuration['ptcomcode']; + $this->secretKey = $configuration['ptcomsecretkey']; + $this->secretWord = $configuration['ptcomsecretword']; + $this->testMode = $configuration['mode']; + } + + /** + * @throws \Exception + */ + public function call($params) + { + try { + $url = self::API_URL; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + + if (!$this->testMode) { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //by default value is 2 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //by default value is 1 + } + + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params, JSON_UNESCAPED_UNICODE)); + $response = curl_exec($ch); + curl_close($ch); + if ($response === false) { + throw new \Exception(sprintf('Curl response :%s', curl_error($ch))); + } + + return json_decode($response, true); + } catch (\Exception $e) { + throw new \Exception(sprintf('Exception ApiCore response: %s', $e->getMessage() + )); + } + } + + /** + * @return array + */ + public function getHeaders(): array + { + + $gmtDate = gmdate('Y-m-d H:i:s'); + $string = strlen($this->sellerId) . $this->sellerId . strlen($gmtDate) . $gmtDate; + $hash = hash_hmac('md5', $string, $this->secretKey); + + $headers[] = 'Content-Type: application/json'; + $headers[] = 'Accept: application/json'; + $headers[] = 'X-Avangate-Authentication: code="' . $this->sellerId . '" date="' . $gmtDate . '" hash="' . $hash . '"'; + + return $headers; + } + + + /** + * @throws \Exception + */ + public function refund($refNo, $params) + { + try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, self::API_URL . $refNo . '/refund/'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params, JSON_UNESCAPED_UNICODE)); + if ($this->testMode) { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //by default value is 2 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //by default value is 1 + } + $response = curl_exec($ch); + curl_close($ch); + if ($response === false) { + throw new \Exception(sprintf('Curl response :%s', curl_error($ch))); + } + + return json_decode($response, true); + } catch (\Exception $e) { + throw new \Exception(sprintf('Exception ApiCore response: %s', $e->getMessage())); + } + } + + /** + * @throws \Exception + */ + public function getOrder($refNo) + { + try { + $url = self::API_URL . $refNo . '/'; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + + if ($this->testMode == 'live') { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //by default value is 2 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //by default value is 1 + } + + $response = curl_exec($ch); + curl_close($ch); + if ($response === false) { + throw new \Exception(sprintf('Curl response :%s', curl_error($ch))); + } + + return json_decode($response, true); + } catch (\Exception $e) { + throw new \Exception(sprintf('Exception ApiCore response: %s', $e->getMessage())); + } + } + +} diff --git a/commerce_tco_convert_plus.zip b/commerce_tco_convert_plus.zip new file mode 100644 index 0000000000000000000000000000000000000000..7a08eb6103325c7ec65d32b72cc48da345f81e38 GIT binary patch literal 8827 zcmbt)1z1#j_w~>vAzf0^-3_8h_s~d)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gy)lmWiC$jMxNZn~v2oq*(OG`zct3A{{0{@wPr7M7{AWaOJ@configuration['ptcomcode']) ? $this->configuration['ptcomcode'] : ''; + $ptcomsecretkey = isset($this->configuration['ptcomsecretkey']) ? $this->configuration['ptcomsecretkey'] : ''; + $ptcomsecretword = isset($this->configuration['ptcomsecretword']) ? $this->configuration['ptcomsecretword'] : ''; + + $form['ptcomcode'] = [ + '#type' => 'textfield', + '#title' => $this->t('Merchant Code'), + '#default_value' => $ptcomcode, + '#description' => $this->t('Use Merchant Code field value from 2Checkout by Verifone Cpanel'), + '#required' => true, + ]; + $form['ptcomsecretkey'] = [ + '#type' => 'textfield', + '#title' => $this->t('Secret Key'), + '#default_value' => $ptcomsecretkey, + '#description' => $this->t('Secret Key from Cpanel'), + '#required' => true, + ]; + $form['ptcomsecretword'] = [ + '#type' => 'textfield', + '#title' => $this->t('Buy Link secret Word'), + '#default_value' => $ptcomsecretword, + '#description' => $this->t('Buy Link secret Word from Cpanel'), + '#required' => false, + ]; + + $form['ptcotest'] = [ + '#type' => 'hidden', + '#title' => $this->t('Mode'), + '#default_value' => $this->getMode(), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) + { + parent::submitConfigurationForm($form, $form_state); + if (!$form_state->getErrors()) { + $values = $form_state->getValue($form['#parents']); + $this->configuration['ptcomcode'] = $values['ptcomcode']; + $this->configuration['ptcomsecretkey'] = $values['ptcomsecretkey']; + $this->configuration['ptcomsecretword'] = $values['ptcomsecretword']; + $this->configuration['ptcotest'] = $values['ptcotest']; + } + } + + /** + * {@inheritdoc} + */ + public function onReturn(OrderInterface $order, Request $request) + { + + $params = $request->query->all(); + if (isset($params['refno'])) { + + //Check if Payment is valid by API request + $mid = $this->configuration['ptcomcode']; + $secretKey = $this->configuration['ptcomsecretkey']; + $test = $this->configuration['ptcotest'] === 'test' ? 1 : 0; + $search = '/orders/' . $params['refno'] . '/'; + + $config = ['mid' => $mid, 'secretKey' => $secretKey, 'test' => $test]; + $response = $this->call($search, [], $config, 'GET'); + if (isset($response['RefNo'])) { + + //Payment is valid. Create drupal Payment + $drupal_payment_state = in_array($response['Status'], ['COMPLETE', 'AUTHRECEIVED']) ? 'completed' : 'authorization'; + + $payment_storage = $this->entityTypeManager->getStorage('commerce_payment'); + $payment = $payment_storage->create([ + 'state' => $drupal_payment_state, + 'amount' => $order->getTotalPrice(), + 'payment_gateway' => $this->entityId, + 'order_id' => $order->id(), + 'test' => $this->getMode() == 'test', + 'remote_id' => $response['RefNo'], + 'remote_state' => $response['Status'], + 'authorized' => $this->time->getRequestTime(), + ]); + $payment->save(); + + \Drupal::messenger()->addMessage($this->t('Your payment was successful with Order id : @orderid and Transaction id : @transaction_id', + ['@orderid' => $order->id(), '@transaction_id' => $response['RefNo']])); + } else { + //Something whent wrong, try payment again + throw new PaymentGatewayException('Invalid order payment reference number!'); + } + } else { + \Drupal::messenger()->addMessage($this->t('Invalid order payment reference number!'), MessengerInterface::TYPE_ERROR); + } + } + + /** + * {@inheritdoc} + */ + public function onCancel(OrderInterface $order, Request $request) + { + $status = $request->get('status'); + \Drupal::messenger()->addMessage($this->t('Payment @status on @gateway but may resume the checkout process here when you are ready.', [ + '@status' => $status, + '@gateway' => $this->getDisplayLabel(), + ]), MessengerInterface::TYPE_ERROR); + } + + + /** + * @throws \Exception + */ + public function call($endpoint, $params, $config, $method = 'POST') + { + try { + $url = self::RESTAPIURL . $endpoint; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders($config['mid'], $config['secretKey'])); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + + if (isset($config['test']) && !$config['test']) { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //by default value is 2 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //by default value is 1 + } + + if ($method === 'POST') { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params, JSON_UNESCAPED_UNICODE)); + } + $response = curl_exec($ch); + curl_close($ch); + if ($response === false) { + throw new \Exception(sprintf('Curl response :%s', curl_error($ch))); + } + + return json_decode($response, true); + } catch (\Exception $e) { + throw new \Exception(sprintf('Exception ApiCore response: %s', $e->getMessage())); + } + } + + public function getHeaders($sellerId, $secretKey) + { + + $gmtDate = gmdate('Y-m-d H:i:s'); + $string = strlen($sellerId) . $sellerId . strlen($gmtDate) . $gmtDate; + $hash = hash_hmac('md5', $string, $secretKey); + + $headers[] = 'Content-Type: application/json'; + $headers[] = 'Accept: application/json'; + $headers[] = 'X-Avangate-Authentication: code="' . $sellerId . '" date="' . $gmtDate . '" hash="' . $hash . '"'; + + return $headers; + } + + public function refundPayment(PaymentInterface $payment, Price $amount = null) + { + + if (!$this->canRefundPayment($payment)) { + \Drupal::messenger()->addMessage($this->t('Order cannot be refunded!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException('Order cannot be refunded!'); + } + + $this->assertPaymentState($payment, ['completed', 'partially_refunded']); + // If not specified, refund the entire amount. + $amount = $amount ?: $payment->getAmount(); + $this->assertRefundAmount($payment, $amount); + $config = [ + 'mid' => $this->configuration['ptcomcode'], + 'secretKey' => $this->configuration['ptcomsecretkey'], + 'test' => $this->configuration['ptcotest'] === 'test' ? 1 : 0, + ]; + try { + $remote_id = $payment->getRemoteId(); + $decimal_amount = $amount->getNumber(); + $order = $this->call('/orders/' . $remote_id . '/', [], $config, 'GET'); + if (!$order) { + \Drupal::messenger()->addMessage($this->t('Invalid transaction ID!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException("Invalid transaction ID"); + } + + if ($amount->getCurrencyCode() !== strtoupper($order['PaymentDetails']['Currency'])) { + \Drupal::messenger()->addMessage($this->t('Cannot refund order in different currencies!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException($this->t('Cannot refund order in different currencies!')); + } + + if ($decimal_amount > $order['GrossPrice']) { + \Drupal::messenger()->addMessage($this->t('You cannot refund more than order total'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException($this->t('You cannot refund more than order total')); + } + + $this->refund($decimal_amount, $order, $config); + } catch (\Exception $e) { + + throw new PaymentGatewayException($e->getMessage()); + } + + // Determine whether payment has been fully or partially refunded. + $old_refunded_amount = $payment->getRefundedAmount(); + $new_refunded_amount = $old_refunded_amount->add($amount); + if ($new_refunded_amount->lessThan($payment->getAmount())) { + $payment->setState('partially_refunded'); + } else { + $payment->setState('refunded'); + } + \Drupal::messenger()->addMessage( + $this->t('@amount @currency refunded with success!', + [ + '@amount' => $decimal_amount, + '@currency' => $amount->getCurrencyCode(), + ])); + $payment->setRefundedAmount($new_refunded_amount); + $payment->save(); + } + + /** + * @throws \Exception + */ + private function refund($amount, $order, $config) + { + + $params = [ + "amount" => $order['GrossPrice'], + "comment" => 'Request by merchant', + "reason" => 'Other', + 'items' => [ + [ + 'Quantity' => 1, + 'LineItemReference' => $order["Items"][0]['LineItemReference'], + 'Amount' => $amount, + ], + ], + ]; + + $response = $this->call('/orders/' . $order['RefNo'] . '/refund/', $params, $config); + if (isset($response['error_code']) && !empty($response['error_code'])) { + + throw new \Exception('Refund failed. Code: ' . $response['error_code']); + } + } + +} diff --git a/commerce_tco_convert_plus/src/PluginForm/TcoCpRedirect/TcoConvertPlusForm.php b/commerce_tco_convert_plus/src/PluginForm/TcoCpRedirect/TcoConvertPlusForm.php new file mode 100644 index 0000000..826ba91 --- /dev/null +++ b/commerce_tco_convert_plus/src/PluginForm/TcoCpRedirect/TcoConvertPlusForm.php @@ -0,0 +1,169 @@ +entity; + $payment_method = $payment->getPaymentGateway(); + + $redirect_method = 'post'; + /** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayInterface $payment_gateway_plugin */ + $payment_gateway_plugin = $payment->getPaymentGateway()->getPlugin(); + //Get Plugin Config + $merchant_id = $payment_gateway_plugin->getConfiguration()['ptcomcode']; + $secret_word = $payment_gateway_plugin->getConfiguration()['ptcomsecretword']; + $mode = $payment_gateway_plugin->getConfiguration()['mode']; + + //Identify Order + $order_id = \Drupal::routeMatch()->getParameter('commerce_order')->id(); + $order = Order::load($order_id); + + + //Gather Shipment && Billing Data + //1. Billing data + $billing_profile = $order->getBillingProfile(); + $address = $order->getBillingProfile()->address->first(); + $billing = [ + 'address' => $address->getAddressLine1(), + 'city' => $address->getLocality(), + 'country' => $address->getCountryCode(), + 'name' => $address->getGivenName() . ' ' . $address->getFamilyName(), + 'phone' => property_exists($billing_profile, 'field_phone') ? $billing_profile->get('field_phone')->value : '0758331990', + 'zip' => $address->getPostalCode(), + 'email' => $order->getEmail(), + 'company-name' => $address->getOrganization(), + 'state' => $address->getAdministrativeArea(), + 'address2' => $address->getAddressLine2(), + ]; + $shipping = []; + //2. Shipment Data + if (property_exists($order, 'shipments')) { + $shipments = $order->get('shipments'); + foreach ($shipments as $shipment) { + $shipment = $shipment->entity; + $ship_address = $shipment->getShippingProfile()->get('address')->first(); + + $shipping = array( + 'ship-name' => $ship_address->getGivenName() . ' ' . $ship_address->getFamilyName(), + 'ship-address' => $ship_address->getAddressLine1(), + 'ship-city' => $ship_address->getLocality(), + 'ship-country' => $ship_address->getCountryCode(), + 'ship-email' => $order->getEmail(), + 'ship-state' => $ship_address->getAdministrativeArea(), + 'ship-address2' => $ship_address->getAddressLine2() + ); + }; + } + + //3. Determine language and + $lang = $address->getLocale(); + if($lang === 'und'){ + $lang = \Drupal::languageManager()->getCurrentLanguage()->getId(); + } + + //4. Generate Buy Link Parameters + $buyLinkParams = []; + $buyLinkParams = array_merge( $buyLinkParams, $billing, $shipping ); + $buyLinkParams['prod'] = 'Cart_'.$order_id; + $buyLinkParams['price'] = round($payment->getAmount()->getNumber(), 2); + $buyLinkParams['qty'] = 1; + $buyLinkParams['type'] = 'PRODUCT'; + $buyLinkParams['tangible'] = 0; + $buyLinkParams['src'] = 'DRUPAL_'.str_replace(".", '_', \Drupal::VERSION); + $buyLinkParams['return-url'] = Url::FromRoute('commerce_payment.checkout.return', ['commerce_order' => $order_id, 'step' => 'payment'], ['absolute' => TRUE])->toString(); + $buyLinkParams['return-type'] = 'redirect'; + $buyLinkParams['expiration'] = time() + ( 3600 * 5 ); + $buyLinkParams['order-ext-ref'] = $payment->getOrderId(); + $buyLinkParams['item-ext-ref'] = date( 'YmdHis' ); + $buyLinkParams['customer-ext-ref'] = $order->getEmail(); + $buyLinkParams['currency'] = $payment->getAmount()->getCurrencyCode(); + $buyLinkParams['language'] = $lang; + $buyLinkParams['test'] = $mode === "test" ? 1 : 0; + $buyLinkParams['merchant'] = $merchant_id; + $buyLinkParams['dynamic'] = 1; + + $signature = $this->getSignature($buyLinkParams, $merchant_id, $secret_word); + $buyLinkParams['signature'] = $signature; + return $this->buildRedirectForm($form, $form_state, self::TCO_BUY_LINK, $buyLinkParams); + } + + /** + * @throws \Exception + */ + public function getSignature($payload, $mid, $sword) + { + $curl = curl_init(); + curl_setopt_array($curl, [ + CURLOPT_URL => self::SIGNATURE_URL, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS => json_encode($payload), + CURLOPT_HTTPHEADER => [ + 'content-type: application/json', + 'cache-control: no-cache', + 'merchant-token: ' . $this->generateJwtToken($mid, $sword), + ] + ]); + $response = curl_exec($curl); + $err = curl_error($curl); + curl_close($curl); + + if ($err) { + throw new \Exception(sprintf('Unable to get proper response from signature generation API. In file %s at line %s', __FILE__, __LINE__)); + } + + $response = json_decode($response, true); + if (JSON_ERROR_NONE !== json_last_error() || !isset($response['signature'])) { + throw new \Exception(sprintf('Unable to get proper response from signature generation API. Signature not set. In file %s at line %s', __FILE__, __LINE__)); + } + + return $response['signature']; + } + + /** + * @return string + */ + private function generateJwtToken($mid, $sword) + { + $header = $this->encode(json_encode(['alg' => 'HS512', 'typ' => 'JWT'])); + $payload = $this->encode(json_encode([ + 'sub' => $mid, + 'iat' => time(), + 'exp' => time() + 3600 + ])); + $signature = $this->encode(hash_hmac('sha512', "$header.$payload", $sword, true)); + + return implode('.', [$header, $payload, $signature]); + } + + /** + * @param $data + * + * @return string|string[] + */ + private function encode($data) + { + return str_replace('=', '', strtr(base64_encode($data), '+/', '-_')); + } +} diff --git a/commerce_tco_inline.zip b/commerce_tco_inline.zip new file mode 100644 index 0000000000000000000000000000000000000000..79f9d4ed5c516dcbf242224ada309aab1d687913 GIT binary patch literal 10671 zcmbVS1z42Z+8w%;2I&~OyF@@b1*B1s?i`Rty1TnW8ip>B4k-yi8bP`w1Sx;yTbeU9J;Vk4OB11uhzIrfF{AGdd0`~jIx<0U|`9US8qiMjBIxo(wSJ2V| zqB$D84U1G3Up39Z_xW0U8+n;9`Okuw1h6nf-VRoP)ZPyhOD!mwX`p=YpBoy%-M=@DvDr`94~&T2Z7`T@#aab!eX42`Zt zNxgb={14)oo9No=*qRuCekde8I5Z&3ASD;dBsmy9)c>xxU%L8}qCB-U1MOh{P^BXC z7~3!#08t;y+efJC5jKOfpoy=kuSP~x%$V0$Q_NV?a=+4R?B~AA=UGY@#cd;FSyK9u zFaQ4MTy-ny@0nX$fedUJO+i+c2H_R=yaZ82 zT;Aw{V#OeYO{B9zVFCjgTJ?NGXSVAJD7)5b-y!%0ZVx7ZOf-VdFgK955E^H#E0pHI z_s*&~Op*o@sw-{2{pNqRsM~%tJfIlbjBT4X37dubX4KK!br2FvgkJy&Fb`iwW2BGx z%&^M~_gePO=%!m3m`EsEnau1*iiS zFKUY?N`#u76@L^(f4CMyP_2jYf)&B&%Y!$ughmkBkrOzF9OmJ+%Y}hDROc@l*N62J zZQH?*?eTQ{pyCYf7m*q^YT03*c6UsENm7?KdzQ6pnm$`x`vh3v|498?tuJLaV1=|1 z>c<%TwWK(|k;D}Ala9VH0HLpt06+jd0KoA3O1~1%6cnl=`(%k3wOMuJ)t+f&l#~hh zlSH+@A~%VJ4o+RMly3-|Y=1+|=ldCtFLuqSV<8>I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RnG7{w;NB+soD>uHI8JOn=)~+i%HI7X3|JE&T=_5Y%394msrU z;@}qgHf_QnmG^Uf$QS#FCeg=PsM1=bOig)Fq7(1)u3GRC6i@m^hCHR2wfI^3(QHlZ z5crh!U~TL1BLwG$>HO)&ixHi(heev9NoU_3WrAGLzP!v03vxb%LnF8-}sS%^%t#W^#Ruk2TpuaQ%y#IVmT zWk0M80zof48>FAW4dzS`^7x;O@1opK9T{gBiY4BR%zC%+ovW|qi&%Zh1&q8j1SB!w zFCXt`ZvYeUW9RzuLj9}wUWUW z9{O!CK9$|;#&60}>7D-yMs^2`_s?Me^4)J^3h?e-W2kvBX8sstH`qT9uDkC1ZB3p3 z5#}#cXZ(*>f1AQnAq2AfSa=J>@UEd zL%(aN-wwU)_dvgj*A#Rc{wB_Hmyc7PN*w~{}(t+KTdCMBMoswXZ+~f zoAPEM`4bZH9VDJVAj$t_Xx;`y;XS_&>851NKfAvE6Cm{+z?c6WQ253Ky^ZWBa&e7x zQ{FK66EfEw|wEu3e-X2_NSElRldiP(N|678e zi2VB~?Y7x^n_Z&iH(b)I5#d#Pm*t;iBEKV3=G9T(pV?iX9Nq?%Er7U|2tzti~lH#bL|x8configuration['tco_inline_code']) ? $this->configuration['tco_inline_code'] : ''; + $tco_inline_secretkey = isset($this->configuration['tco_inline_secret_key']) ? $this->configuration['tco_inline_secret_key'] : ''; + $tco_inline_secretword = isset($this->configuration['tco_inline_secret_word']) ? $this->configuration['tco_inline_secret_word'] : ''; + $tco_inline_template = isset($this->configuration['tco_inline_template']) ? $this->configuration['tco_inline_template'] : 'inline-one-step'; + // $tco_inline_test = isset($this->configuration['tco_inline_test']) ? $this->configuration['tco_inline_test'] : ''; + + $form['tco_inline_code'] = [ + '#type' => 'textfield', + '#title' => $this->t('Merchant Code'), + '#default_value' => $tco_inline_code, + '#description' => $this->t('Use Merchant code field value from 2Checkout by Verifone Cpanel'), + '#required' => true, + ]; + $form['tco_inline_secret_key'] = [ + '#type' => 'textfield', + '#title' => $this->t('Secret Key'), + '#default_value' => $tco_inline_secretkey, + '#description' => $this->t('Secret key from Cpanel'), + '#required' => true, + ]; + $form['tco_inline_secret_word'] = [ + '#type' => 'textfield', + '#title' => $this->t('Secret Word'), + '#default_value' => $tco_inline_secretword, + '#description' => $this->t('Buy Link secret word from Cpanel'), + '#required' => false, + ]; + $form['tco_inline_template'] = [ + '#type' => 'radios', + '#title' => $this->t('Template'), + '#default_value' => $tco_inline_template, + '#description' => $this->t('Choose between a multi-step or a one-step inline checkout.'), + '#required' => true, + '#options' => [ + 'inline-one-step' => $this->t('One step inline'), + 'inline' => $this->t('Multi step inline'), + ], + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) + { + parent::submitConfigurationForm($form, $form_state); + + if (!$form_state->getErrors()) { + $values = $form_state->getValue($form['#parents']); + $this->configuration['tco_inline_code'] = $values['tco_inline_code']; + $this->configuration['tco_inline_secret_key'] = $values['tco_inline_secret_key']; + $this->configuration['tco_inline_secret_word'] = $values['tco_inline_secret_word']; + $this->configuration['tco_inline_template'] = $values['tco_inline_template']; + // $this->configuration['tco_inline_test'] = $values['tco_inline_test']; + } + } + + + /** + * {@inheritdoc} + * @throws \Exception + */ + public function onReturn(OrderInterface $order, Request $request) + { + + $reference = $request->get('refno'); + $api = new ApiHelper($this->configuration); + if (isset($reference)) { + + //Check if Payment is valid by API request + $response = $api->getOrder($reference); + if (isset($response['RefNo'])) { + + //Payment is valid. Create drupal Payment + $remote_status = $response['Status']; + $drupal_payment_state = in_array($response['Status'], ['COMPLETE', 'AUTHRECEIVED']) ? 'completed' : 'authorization'; + $payment_storage = $this->entityTypeManager->getStorage('commerce_payment'); + $payment = $payment_storage->create([ + 'state' => $drupal_payment_state, + 'amount' => $order->getTotalPrice(), + 'payment_gateway' => $this->entityId, + 'order_id' => $order->id(), + 'test' => $this->getMode() == 'test', + 'remote_id' => $response['RefNo'], + 'remote_state' => $remote_status, + 'authorized' => $this->time->getRequestTime(), + ]); + $payment->save(); + + \Drupal::messenger()->addMessage($this->t('Your payment was successful with Order id : @orderid and 2Checkout transaction id : @transaction_id', + ['@orderid' => $order->id(), '@transaction_id' => $reference])); + + } else { + //Something went wrong, try payment again + throw new PaymentGatewayException('Invalid order payment reference number!'); + } + } else { + + \Drupal::messenger()->addMessage($this->t('Invalid order payment reference number!'), MessengerInterface::TYPE_ERROR); + } + } + + /** + * {@inheritdoc} + */ + public function onCancel(OrderInterface $order, Request $request) + { + $status = $request->get('status'); + + \Drupal::messenger()->addMessage( + $this->t('Payment @status on @gateway but may resume the checkout process here when you are ready.', [ + '@status' => $status, + '@gateway' => $this->getDisplayLabel(), + ]), MessengerInterface::TYPE_ERROR); + } + + public function refundPayment(PaymentInterface $payment, Price $amount = null) + { + + if (!$this->canRefundPayment($payment)) { + \Drupal::messenger()->addMessage($this->t('Order cannot be refunded!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException('Order cannot be refunded!'); + } + + $this->assertPaymentState($payment, ['completed', 'partially_refunded']); + // If not specified, refund the entire amount. + $amount = $amount ?: $payment->getAmount(); + $this->assertRefundAmount($payment, $amount); + + try { + $remote_id = $payment->getRemoteId(); + $decimal_amount = $amount->getNumber(); + $api = new ApiHelper($this->configuration); + $order = $api->getOrder($remote_id); + if (!$order) { + \Drupal::messenger()->addMessage($this->t('Invalid transaction ID!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException("Invalid transaction ID"); + } + + if ($amount->getCurrencyCode() !== strtoupper($order['PaymentDetails']['Currency'])) { + \Drupal::messenger()->addMessage($this->t('Cannot refund order in different currencies!'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException($this->t('Cannot refund order in different currencies!')); + } + + if ($decimal_amount > $order['GrossPrice']) { + \Drupal::messenger()->addMessage($this->t('You cannot refund more than order total'), MessengerInterface::TYPE_ERROR); + throw new PaymentGatewayException($this->t('You cannot refund more than order total')); + } + + $this->refund($decimal_amount, $order, $api); + } catch (\Exception $e) { + + throw new PaymentGatewayException($e->getMessage()); + } + + // Determine whether payment has been fully or partially refunded. + $old_refunded_amount = $payment->getRefundedAmount(); + $new_refunded_amount = $old_refunded_amount->add($amount); + if ($new_refunded_amount->lessThan($payment->getAmount())) { + $payment->setState('partially_refunded'); + } else { + $payment->setState('refunded'); + } + \Drupal::messenger()->addMessage( + $this->t('@amount @currency refunded with success!', + [ + '@amount' => $decimal_amount, + '@currency' => $amount->getCurrencyCode(), + ])); + $payment->setRefundedAmount($new_refunded_amount); + $payment->save(); + } + + /** + * @throws \Exception + */ + private function refund($amount, $order, $api) + { + + $params = [ + "amount" => $order['GrossPrice'], + "comment" => 'Request by merchant', + "reason" => 'Other', + 'items' => [ + [ + 'Quantity' => 1, + 'LineItemReference' => $order["Items"][0]['LineItemReference'], + 'Amount' => $amount, + ], + ], + ]; + + $response = $api->refund($order['RefNo'], $params); + if (isset($response['error_code']) && !empty($response['error_code'])) { + \Drupal::messenger()->addMessage($this->t('Refund failed. Reason: @message', ['@message' => $response['message']]), + MessengerInterface::TYPE_ERROR); + throw new \Exception('Refund failed. Reason: ' . $response['message']); + } + } + +} diff --git a/commerce_tco_inline/src/PluginForm/TcoInlineRedirect/TcoInlineForm.php b/commerce_tco_inline/src/PluginForm/TcoInlineRedirect/TcoInlineForm.php new file mode 100644 index 0000000..10662b6 --- /dev/null +++ b/commerce_tco_inline/src/PluginForm/TcoInlineRedirect/TcoInlineForm.php @@ -0,0 +1,123 @@ +entity; + + /** @var OffsitePaymentGatewayInterface $payment_gateway_plugin */ + $payment_gateway_plugin = $payment->getPaymentGateway()->getPlugin(); + + //Get Plugin Config + $merchant_id = $payment_gateway_plugin->getConfiguration()['tco_inline_code']; + $test = $payment_gateway_plugin->getConfiguration()['mode']; + $customization = $payment_gateway_plugin->getConfiguration()['tco_inline_template']; + + //Identify Order + $order_id = \Drupal::routeMatch()->getParameter('commerce_order')->id(); + $order = Order::load($order_id); + + //Instantiate the helper + $api = new ApiHelper($payment_gateway_plugin->getConfiguration()); + + //Gather Shipment && Billing Data + //1. Billing data + $billing_profile = $order->getBillingProfile(); + $address = $order->getBillingProfile()->address->first(); + $billingAddressData = [ + 'name' => $address->getGivenName() . ' ' . $address->getFamilyName(), + 'phone' => property_exists($billing_profile, 'field_phone') ? $billing_profile->get('field_phone')->value : 'xxxxxxxxxxxxx', + 'country' => $address->getCountryCode(), + 'state' => $address->getAdministrativeArea() !== null ? $address->getAdministrativeArea() : 'XX', + 'email' => $order->getEmail(), + 'address' => $address->getAddressLine1(), + 'address2' => $address->getAddressLine2(), + 'city' => $address->getLocality(), + 'company-name' => $address->getOrganization(), + 'zip' => $address->getPostalCode(), + ]; + $shippingAddressData = []; + //2. Shipment Data + if (property_exists($order, 'shipments')) { + $shipments = $order->get('shipments'); + foreach ($shipments as $shipment) { + $shipment = $shipment->entity; + $ship_address = $shipment->getShippingProfile()->get('address')->first(); + $shippingAddressData = [ + 'ship-name' => $ship_address->getGivenName() . ' ' . $ship_address->getFamilyName(), + 'ship-country' => $ship_address->getCountryCode(), + 'ship-state' => $ship_address->getAdministrativeArea() !== null ? $ship_address->getAdministrativeArea() : 'XX', + 'ship-city' => $ship_address->getLocality(), + 'ship-email' => $order->getEmail(), + 'ship-phone' => property_exists($ship_address, 'field_phone') ? $ship_address->get('field_phone')->value : 'xxxxxxxxxxxxx', + 'ship-address' => $ship_address->getAddressLine1(), + 'ship-address2' => $ship_address->getAddressLine2(), + ]; + } + } + + //3. Determine language + $lang = $address->getLocale(); + if ($lang === 'und') { + $lang = \Drupal::languageManager()->getCurrentLanguage()->getId(); + } + + $payload['products'][] = [ + 'type' => 'PRODUCT', + 'name' => 'Cart_' . $order_id, + 'price' => round($payment->getAmount()->getNumber(), 2), + 'tangible' => 0, + 'qty' => 1, + ]; + $payload['return-method'] = [ + 'type' => 'redirect', + 'url' => Url::FromRoute('commerce_payment.checkout.return', ['commerce_order' => $order_id, 'step' => 'payment'], ['absolute' => true])->toString(), + ]; + + $payload['currency'] = $payment->getAmount()->getCurrencyCode(); + $payload['language'] = $lang; + $payload['test'] = $test == 'test' ? 1 : 0; + $payload['order-ext-ref'] = $order_id; + $payload['customer-ext-ref'] = $order->getEmail(); + $payload['src'] = 'DRUPAL_' . str_replace(".", '_', \Drupal::VERSION); + $payload['mode'] = 'DYNAMIC'; + $payload['dynamic'] = '1'; + $payload['country'] = $address->getCountryCode(); + $payload['merchant'] = $merchant_id; + $payload['shipping_address'] = ($shippingAddressData); + $payload['billing_address'] = ($billingAddressData); + $payload['signature'] = $api->getSignature($payload); + $payload['customization'] = $customization; + + $form['#attached']['drupalSettings']['tco_inline_payload'] = $payload; + $form['#attached']['drupalSettings']['return_url'] = $form['#return_url']; + $form['#attached']['library'][] = 'commerce_tco_inline/commerce_tco_inline'; + + return $form; + } + +} diff --git a/commerce_tco_inline/src/Twocheckout/ApiHelper.php b/commerce_tco_inline/src/Twocheckout/ApiHelper.php new file mode 100644 index 0000000..3de1f96 --- /dev/null +++ b/commerce_tco_inline/src/Twocheckout/ApiHelper.php @@ -0,0 +1,179 @@ +sellerId = $configuration['tco_inline_code']; + $this->secretKey = $configuration['tco_inline_secret_key']; + $this->secretWord = $configuration['tco_inline_secret_word']; + $this->testMode = $configuration['mode']; + } + + /** + * @throws \Exception + */ + public function getOrder($refNo) + { + try { + $url = self::API_URL . $refNo . '/'; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + + if ($this->testMode == 'live') { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //by default value is 2 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //by default value is 1 + } + + $response = curl_exec($ch); + curl_close($ch); + if ($response === false) { + throw new \Exception(sprintf('Curl response :%s', curl_error($ch))); + } + + return json_decode($response, true); + } catch (\Exception $e) { + throw new \Exception(sprintf('Exception ApiCore response: %s', $e->getMessage())); + } + } + + /** + * @throws \Exception + */ + public function getSignature($payload) + { + $curl = curl_init(); + + curl_setopt_array($curl, [ + CURLOPT_URL => self::SIGNATURE_URL, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS => json_encode($payload), + CURLOPT_HTTPHEADER => [ + 'content-type: application/json', + 'cache-control: no-cache', + 'merchant-token: ' . $this->generateJwtToken(), + ], + ]); + $response = curl_exec($curl); + $err = curl_error($curl); + curl_close($curl); + if ($err) { + throw new \Exception(sprintf('Unable to get proper response from signature generation API. In file %s at line %s', __FILE__, __LINE__)); + } + $response = json_decode($response, true); + if (JSON_ERROR_NONE !== json_last_error() || !isset($response['signature'])) { + throw new \Exception(sprintf('Unable to get proper response from signature generation API. Signature not set. In file %s at line %s', __FILE__, __LINE__)); + } + + return $response['signature']; + } + + /** + * @return array + */ + public function getHeaders(): array + { + + $gmtDate = gmdate('Y-m-d H:i:s'); + $string = strlen($this->sellerId) . $this->sellerId . strlen($gmtDate) . $gmtDate; + $hash = hash_hmac('md5', $string, $this->secretKey); + + $headers[] = 'Content-Type: application/json'; + $headers[] = 'Accept: application/json'; + $headers[] = 'X-Avangate-Authentication: code="' . $this->sellerId . '" date="' . $gmtDate . '" hash="' . $hash . '"'; + + return $headers; + } + + /** + * @return string + */ + private function generateJwtToken(): string + { + $header = $this->encode(json_encode(['alg' => 'HS512', 'typ' => 'JWT'])); + $payload = $this->encode(json_encode(['sub' => $this->sellerId, 'iat' => time(), 'exp' => time() + 3600])); + $signature = $this->encode(hash_hmac('sha512', "$header.$payload", $this->secretWord, true)); + + return implode('.', [$header, $payload, $signature]); + } + + /** + * @param $data + * + * @return string|string[] + */ + private function encode($data) + { + return str_replace('=', '', strtr(base64_encode($data), '+/', '-_')); + } + + + /** + * @throws \Exception + */ + public function refund($refNo, $params) + { + try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, self::API_URL . $refNo . '/refund/'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params, JSON_UNESCAPED_UNICODE)); + if ($this->testMode) { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //by default value is 2 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //by default value is 1 + } + $response = curl_exec($ch); + curl_close($ch); + if ($response === false) { + throw new \Exception(sprintf('Curl response :%s', curl_error($ch))); + } + + return json_decode($response, true); + } catch (\Exception $e) { + throw new \Exception(sprintf('Exception ApiCore response: %s', $e->getMessage())); + } + } + +}