├── .dockerignore
├── src
├── assets
│ ├── css
│ │ ├── pairing.css
│ │ └── token.css
│ ├── img
│ │ ├── icon.png
│ │ ├── logo.png
│ │ └── ajax-loader.gif
│ ├── screenshot-1.png
│ ├── screenshot-2.png
│ ├── screenshot-3.png
│ ├── screenshot-4.png
│ ├── screenshot-5.png
│ └── js
│ │ └── pairing.js
├── class-wc-gateway-bitpay.php
├── templates
│ ├── paymentStatus.tpl
│ ├── token.tpl
│ └── pairing.tpl
├── uninstall.php
├── languages
│ └── btcpay-for-woocommerce.pot
├── readme.txt
└── class-wc-gateway-btcpay.php
├── .travis.yml
├── docs
└── img
│ ├── admin.png
│ ├── token.png
│ ├── pairingcode.png
│ └── ordersettings.png
├── woocommerce
├── docker-bitcoin-cli.ps1
├── docker-litecoin-cli.ps1
├── README.md
├── Dockerfile
└── docker-compose.yml
├── tests
└── EmptyTest.php
├── docker-build.ps1
├── phpunit.xml
├── .gitignore
├── .github
└── ISSUE_TEMPLATE
│ ├── ---feature-request.md
│ └── ----bug-report-.md
├── woocommerce-plugin.code-workspace
├── package.json
├── composer.json
├── LICENSE
├── Dockerfile
├── wp-repo-publish.ps1
├── Gruntfile.js
├── GUIDE.md
├── README.md
└── CHANGELOG.md
/.dockerignore:
--------------------------------------------------------------------------------
1 | docker-build.ps1
2 | dist/
3 | woocommerce/
4 | Dockerfile
--------------------------------------------------------------------------------
/src/assets/css/pairing.css:
--------------------------------------------------------------------------------
1 | .btcpay-pairing--hidden {
2 | display: none;
3 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 | php:
3 | - 5.4
4 | - 5.5
5 | - 5.6
6 | - hhvm
--------------------------------------------------------------------------------
/docs/img/admin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/docs/img/admin.png
--------------------------------------------------------------------------------
/docs/img/token.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/docs/img/token.png
--------------------------------------------------------------------------------
/src/class-wc-gateway-bitpay.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/assets/img/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/img/icon.png
--------------------------------------------------------------------------------
/src/assets/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/img/logo.png
--------------------------------------------------------------------------------
/docs/img/pairingcode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/docs/img/pairingcode.png
--------------------------------------------------------------------------------
/docs/img/ordersettings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/docs/img/ordersettings.png
--------------------------------------------------------------------------------
/src/assets/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/screenshot-1.png
--------------------------------------------------------------------------------
/src/assets/screenshot-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/screenshot-2.png
--------------------------------------------------------------------------------
/src/assets/screenshot-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/screenshot-3.png
--------------------------------------------------------------------------------
/src/assets/screenshot-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/screenshot-4.png
--------------------------------------------------------------------------------
/src/assets/screenshot-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/screenshot-5.png
--------------------------------------------------------------------------------
/src/assets/img/ajax-loader.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/btcpayserver/woocommerce-plugin/HEAD/src/assets/img/ajax-loader.gif
--------------------------------------------------------------------------------
/woocommerce/docker-bitcoin-cli.ps1:
--------------------------------------------------------------------------------
1 | docker exec -ti woocommerce_bitcoind_1 bitcoin-cli -regtest -conf="/data/bitcoin.conf" -datadir="/data" $args
--------------------------------------------------------------------------------
/woocommerce/docker-litecoin-cli.ps1:
--------------------------------------------------------------------------------
1 | docker exec -ti woocommerce_litecoind litecoin-cli -regtest -conf="/data/litecoin.conf" -datadir="/data" $args
2 |
--------------------------------------------------------------------------------
/tests/EmptyTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, true);
7 | }
8 | }
--------------------------------------------------------------------------------
/src/templates/paymentStatus.tpl:
--------------------------------------------------------------------------------
1 |
6 |
7 | {$paymentStatus}
8 |
9 |
3 | {$statusTitle}
4 |
5 |
%s"
75 | msgstr ""
76 |
77 | #: class-wc-gateway-btcpay.php:359
78 | msgid "Notification URL"
79 | msgstr ""
80 |
81 | #: class-wc-gateway-btcpay.php:361
82 | msgid "BTCPay will send IPNs for orders to this URL with the BTCPay invoice data"
83 | msgstr ""
84 |
85 | #: class-wc-gateway-btcpay.php:367
86 | msgid "Redirect URL"
87 | msgstr ""
88 |
89 | #: class-wc-gateway-btcpay.php:369
90 | msgid "After paying the BTCPay invoice, users will be redirected back to this URL"
91 | msgstr ""
92 |
93 | #: class-wc-gateway-btcpay.php:375
94 | msgid "Additional token configuration"
95 | msgstr ""
96 |
97 | #: class-wc-gateway-btcpay.php:377
98 | msgid "You can configure additional tokens here, one per line. e.g. \"HAT;Hat Token;promotion\" See documentation for details. Each one will be available as their own payment method."
99 | msgstr ""
100 |
101 | #: class-wc-gateway-btcpay.php:382
102 | msgid "Additional tokens: Enforce payment tokens"
103 | msgstr ""
104 |
105 | #: class-wc-gateway-btcpay.php:384
106 | msgid "Limit default payment methods to listed \"payment\" tokens."
107 | msgstr ""
108 |
109 | #: class-wc-gateway-btcpay.php:387
110 | msgid "This will override the default btcpay payment method (defaults to all supported by BTCPay Server) and enforce to tokens of type \"payment\". This is useful if you want full control on what is available on BTCPay Server payment page."
111 | msgstr ""
112 |
113 | #: class-wc-gateway-btcpay.php:393
114 | msgid "This plugin version is %s and your PHP version is %s. If you need assistance, please come on our chat https://chat.btcpayserver.org. Thank you for using BTCPay!"
115 | msgstr ""
116 |
117 | #: class-wc-gateway-btcpay.php:1173
118 | msgid "BTCPay invoice paid. Awaiting network confirmation and payment completed status."
119 | msgstr ""
120 |
121 | #: class-wc-gateway-btcpay.php:1182
122 | msgid "BTCPay invoice confirmed. Awaiting payment completed status."
123 | msgstr ""
124 |
125 | #: class-wc-gateway-btcpay.php:1194
126 | msgid "BTCPay invoice payment completed. Payment credited to your merchant account."
127 | msgstr ""
128 |
129 | #: class-wc-gateway-btcpay.php:1204
130 | msgid "Bitcoin payment is invalid for this order! The payment was not confirmed by the network within on time. Do not ship the product for this order!"
131 | msgstr ""
132 |
133 | #: class-wc-gateway-btcpay.php:1211
134 | msgid "Bitcoin payment has expired for this order! The payment was not broadcasted before its expiration. Do not ship the product for this order!"
135 | msgstr ""
136 |
137 | #: class-wc-gateway-btcpay.php:1230
138 | msgid "A payment has arrived late for this order!"
139 | msgstr ""
140 |
141 | #: class-wc-gateway-btcpay.php:1231
142 | msgid "A payment has been received after expiration"
143 | msgstr ""
144 |
145 | #: class-wc-gateway-btcpay.php:1238
146 | msgid "The invoice has expired while a partial payment has been sent"
147 | msgstr ""
148 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | | :warning: WARNING |
2 | |:---------------------------|
3 | | **This plugin, based on the legacy BitPay API and has been discontinued and will only receive security updates. While it will continue to work just fine it won't get any new features. We encourage you use our more modern and actively developed [BTCPay for WooCommerce V2](https://wordpress.org/plugins/btcpay-greenfield-for-woocommerce/) plugin that builds on top of the more feature rich BTCPay Server Greenfield API.** |
4 |
5 |
6 |
7 | ## Quick Start Guide
8 |
9 | To get up and running with our plugin quickly, see the GUIDE here: https://docs.btcpayserver.org/integrations/woocommerce
10 |
11 | ## Brief Description
12 |
13 | Add the ability to accept bitcoin in WooCommerce via BTCPayServer.
14 | This plugin is also available through the [wordpress store](https://wordpress.org/plugins/btcpay-for-woocommerce/).
15 |
16 | ## Detail Description
17 |
18 | Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for a highly resilient value transfer infrastructure, and this allows merchants to gain greater profits.
19 |
20 | This is because there are little to no fees for transferring Bitcoins from one person to another. Unlike other payment methods, Bitcoin payments cannot be reversed, so once you are paid you can ship! No waiting days for a payment to clear.
21 |
22 | ## Development
23 |
24 | ### Setup
25 |
26 | * NodeJS & NPM
27 | * Grunt
28 | * Composer
29 |
30 | Clone the repo:
31 | ```bash
32 | $ git clone https://github.com/btcpayserver/woocommerce-plugin
33 | $ cd woocommerce-plugin
34 | ```
35 |
36 | Install the dependencies:
37 | ```bash
38 | $ npm install
39 | $ curl -sS https://getcomposer.org/installer | php
40 | $ ./composer.phar install
41 | ```
42 |
43 | ### Build
44 |
45 | Perform the [setup](#Setup), then:
46 | ```bash
47 | $ ./node_modules/.bin/grunt build
48 | # Outputs plugin at dist/woocommerce-plugin
49 | # Outputs plugin archive at dist/woocommerce-plugin.zip
50 | ```
51 |
52 | ## Support
53 |
54 | ### BTCPay Support
55 |
56 | * Last Version Tested: Wordpress 4.8.1 WooCommerce 3.1.2
57 | * [GitHub Issues](https://github.com/btcpayserver/woocommerce-plugin/issues)
58 | * Open an issue if you are having issues with this plugin.
59 | * [Support](https://docs.btcpayserver.org)
60 | * BTCPay merchant support documentation
61 |
62 | ### WooCommerce Support
63 |
64 | * [Homepage](http://www.woothemes.com/woocommerce/)
65 | * [Documentation](http://docs.woothemes.com)
66 | * [Support](https://support.woothemes.com)
67 |
68 | ## Troubleshooting
69 |
70 | 1. Ensure a valid SSL certificate is installed on your server. Also ensure your root CA cert is updated. If your CA cert is not current, you will see curl SSL verification errors.
71 | 2. Verify that your web server is not blocking POSTs from servers it may not recognize. Double check this on your firewall as well, if one is being used.
72 | 3. Check the version of this plugin against the official plugin repository to ensure you are using the latest version. Your issue might have been addressed in a newer version! See the [Releases](https://github.com/btcpayserver/woocommerce-plugin/releases) page for the latest.
73 | 4. If all else fails, enable debug logging in the plugin options and open an issue or contact the [community](https://github.com/btcpayserver/btcpayserver#-community).
74 |
75 | **TIP**: When contacting support it will help us is you provide:
76 |
77 | * WordPress and WooCommerce Version
78 | * Other plugins you have installed
79 | * Some plugins do not play nice
80 | * Configuration settings for the plugin (Most merchants take screen grabs)
81 | * Any log files that will help
82 | * Web server error logs
83 | * Screen grabs of error message if applicable.
84 |
85 | ## build with docker
86 |
87 | Powershell:
88 | ```
89 | ./docker-build.ps1
90 | ```
91 |
92 | Linux:
93 | ```
94 | rm -rf dist/
95 | docker build -t woocommerce_btcpay .
96 | docker run -ti -v "`pwd`/dist:/app/dist" --rm woocommerce_btcpay
97 | echo "Output available in `pwd`/dist/btcpay-for-woocommerce.zip"
98 | ```
99 |
100 | ## Common errors
101 |
102 | ### SSL certificate problem: unable to get local issuer certificate
103 |
104 | This can come in two conditions:
105 |
106 | * Your BTCPayServer is running on a test certificate
107 | * You have not installed root certificates on the wordpress host
108 |
109 | In the first case, please, make sure a valid SSL certificates is installed on your BTCPayServer. You can check this is the case by browsing to the BTCPayServer page, and check there is no browser warnings.
110 |
111 | In the second case run,
112 |
113 | ```
114 | sudo apt-get install ca-certificates
115 | ```
116 |
117 | ## Contribute
118 |
119 | Would you like to help with this project? Great! You don't have to be a developer, either. If you've found a bug or have an idea for an improvement, please open an [issue](https://github.com/btcpayserver/woocommerce-plugin/issues) and tell us about it.
120 |
121 | If you *are* a developer wanting contribute an enhancement, bugfix or other patch to this project, please fork this repository and submit a pull request detailing your changes. We review all PRs!
122 |
123 | This open source project is released under the [MIT license](http://opensource.org/licenses/MIT) which means if you would like to use this project's code in your own project you are free to do so. Speaking of, if you have used our code in a cool new project we would like to hear about it! Please get [in contact](https://github.com/btcpayserver/btcpayserver#-community).
124 |
125 | ## License
126 |
127 | Please refer to the [LICENSE](https://github.com/btcpayserver/woocommerce-plugin/blob/master/LICENSE) file that came with this project.
128 |
--------------------------------------------------------------------------------
/src/assets/js/pairing.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license Copyright 2011-2014 BitPay Inc., MIT License
3 | * see https://github.com/bitpay/woocommerce-bitpay/blob/master/LICENSE
4 | */
5 |
6 | 'use strict';
7 |
8 | (function ( $ ) {
9 |
10 | $(function () {
11 |
12 | /**
13 | * Update the API Token helper link on Network selection
14 | */
15 |
16 | var isValidUrl = function(url){
17 | if(typeof url === "string" && (url.indexOf("http://") == 0 || url.indexOf("https://") == 0)){
18 | return true;
19 | }
20 | return false;
21 | }
22 |
23 | var formatUrl = function(url){
24 | if(typeof url === "string"){
25 | return url.replace(/^(.+?)\/*?$/, "$1");
26 | }
27 | return null;
28 | }
29 |
30 |
31 | var updatePairingLink = function (e) {
32 | var txtPairingUrl = $('.btcpay-url');
33 | var pairingLinkElement = $('.btcpay-pairing__link');
34 | // var requestpairingButton = $('.btcpay-pairing__request_pairing');
35 |
36 | var pairingLinkMessage = $(".btcpay-pairing__link_message")
37 | if(txtPairingUrl.length == 0 ){
38 | return;
39 | }
40 |
41 | var url = formatUrl(txtPairingUrl.val());
42 | if(isValidUrl(url))
43 | {
44 | url = url + "/api-tokens";
45 | pairingLinkElement
46 | .attr('href', url)
47 | .html(url)
48 | .show();
49 | // requestpairingButton.show();
50 | pairingLinkMessage.hide();
51 | }
52 | else
53 | {
54 | // requestpairingButton.hide();
55 | pairingLinkElement.hide();
56 | pairingLinkMessage.show().text('Please enter BTCPay Url first');
57 | }
58 | };
59 |
60 |
61 | // var requestPairing = function(){
62 |
63 | // var pairingLinkElement = $('.btcpay-pairing__link');
64 | // if(pairingLinkElement.is(":hidden")){
65 | // return;
66 | // }
67 | // var url = pairingLinkElement.attr("href");
68 | // var btcpayWindow = window.open(url, "_blank");
69 | // btcpayWindow.focus();
70 |
71 | // $(btcpayWindow).on("message", function(e){
72 | // if(url.indexOf(e.origin) > 0){
73 | // try{
74 | // var data = JSON.stringify(e.data);
75 | // if(data && data.event == 'btcpay-pairing-sin' && data.pairingCode){
76 | // if(pairingCode){
77 | // btcpayWindow.close();
78 | // $(".btcpay-pairing__code").val(data.pairingCode);
79 | // $(".btcpay-pairing__find").click();
80 | // }
81 | // }
82 | // }catch{
83 |
84 | // }
85 | // }
86 | // });
87 | // }
88 |
89 | // $('.btcpay-pairing__request_pairing').on('click', requestPairing);
90 |
91 |
92 | updatePairingLink();
93 | $('#btcpay_api_token_form').on('input', '.btcpay-url', updatePairingLink);
94 |
95 | /**
96 | * Try to pair with BtcPay using an entered pairing code
97 | */
98 | $('#btcpay_api_token_form').on('click', '.btcpay-pairing__find', function (e) {
99 |
100 | // Don't submit any forms or follow any links
101 | e.preventDefault();
102 |
103 | // Hide the pairing code form
104 | $('.btcpay-pairing').hide();
105 | $('.btcpay-pairing').after('You have been paired with your BtcPay store!
You have revoked your token!
52 |
53 | To integrate BTCPay Server into an existing WooCommerce store, follow the steps below.
54 |
55 | ### 1. Install BTCPay WooCommerce Plugin ###
56 |
57 | ### 2. Deploy BTCPay Server ###
58 |
59 | To launch your BTCPay server, you can self-host it, or use a third party host.
60 |
61 | #### 2.1 Self-hosted BTCPay ####
62 |
63 | There are various ways to [launch a self-hosted BTCPay](https://github.com/btcpayserver/btcpayserver-doc#deployment). If you do not have technical knowledge, use the [web-wizard method](https://launchbtcpay.lunanode.com) and follow the video below.
64 |
65 | https://www.youtube.com/watch?v=NjslXYvp8bk
66 |
67 | For the self-hosted solutions, you\'ll have to wait for your node to sync fully before proceeding to step 3.
68 |
69 | #### 2.2 Third-party host ####
70 |
71 | Those who want to test BTCPay out, or are okay with the limitations of a third-party hosting (dependency and privacy, as well as lack of some features) can use a one of many [third-party hosts](ThirdPartyHosting.md).
72 |
73 | The video below shows you how to connect your store to such host.
74 |
75 | https://www.youtube.com/watch?v=IT2K8It3S3o
76 |
77 | ### 3. Pairing the store ###
78 |
79 | BTCPay WooCommerce plugin is a bridge between your server (payment processor) and your e-commerce store. No matter if you\'re using a self-hosted or third-party solution from step 2, the pairing process is identical.
80 |
81 | Go to your store dashboard. WooCommerce > Settings > Payments. Click BTCPay.
82 |
83 | 1. In the field, enter the full URL of your host (including the https) – https://btcpay.mydomain.com
84 | 2. Click on the generated link which will redirect you back to your BTCPay Server.
85 | 3. Click on request pairing
86 | 4. Approve the pairing
87 | 5. Copy the pairing code
88 | 6. Go back to your store and paste the pairing code
89 | 7. Click “Pair”
90 | 8. When you see the image, it means you successfully paired your server and your store.
91 |
92 | The process of pairing a store with BTCPay is explained in a video below, starting at 1:59
93 |
94 | https://youtu.be/IT2K8It3S3o?t=119
95 |
96 | ### 4. Connecting your wallet ###
97 |
98 | No matter if you're using self-hosted or server hosted by a third-party, the process of configuring your wallet is the same.
99 |
100 | https://www.youtube.com/watch?v=xX6LyQej0NQ
101 |
102 | ### 5. Testing the checkout ###
103 |
104 | Making a small test-purchase from your own store, will give you a piece of mind. Always make sure that everything is set up correctly before going live. The final video, guides you through the steps of setting a gap limit in your Electrum wallet and testing the checkout process.
105 |
106 | https://www.youtube.com/watch?v=Fi3pYpzGmmo
107 |
108 | Depending on your business model and store settings, you may want to [configure your order statuses](https://nbitstack.com/t/how-to-set-up-order-statuses-in-woocommerce-and-btcpay/67).
109 |
110 | == Frequently Asked Questions ==
111 |
112 | You'll find extensive documentation and answers to many of your questions on [docs.btcpayserver.org](https://docs.btcpayserver.org/).
113 |
114 | == Screenshots ==
115 |
116 | 1. The BTCPay Server invoice. Your customers will see this at the checkout. They can pay from their wallet by scanning a QR or copy/pasting it manually into the wallet.
117 | 2. Customizable plugin interface allows store owners to adjust store statuses according to their needs.
118 | 3. Customer will see the pay with Bitcoin button at the checkout.Text can be customized.
119 | 4. Example of sucessfuly paid invoice.
120 | 5. Example of an easy-embeddable HTML donation payment button.
121 | 6. Example of the PoS app you can launch.
122 |
123 | == Changelog ==
124 |
125 | ## 3.0.16
126 |
127 | - Updating readme with legacy notice and link to new V2 version.
128 |
129 | ## 3.0.15
130 |
131 | - Fix: the plugin should not restrain the available currencies @NicolasDorier
132 |
133 | ## 3.0.14
134 |
135 | - Fix: the plugin would to work on some domains, due to a https error @ndeet
136 |
137 | ## 3.0.13
138 | - make plugin able to expand BTCPay payment methods as individual woocommerce payment methods (see https://docs.btcpayserver.org/FAQ/FAQ-Integrations/#how-to-configure-additional-token-support) @ndeet
139 | - allow plugin localization @janhn
140 |
141 | ## 3.0.12
142 | - Make the plugin works better with custom order number @dennisreimann @ndeet
143 |
144 | ## 3.0.11
145 | Empty release to make wordpress plugin store know we are still alive
146 |
147 | ## 3.0.10
148 | Fixed
149 | - Fix woocommerce admin compatibility
150 | - Add country code in btcpay invoice
151 |
152 | ## 3.0.8
153 | Fixed
154 | - Fix bug with Woocommerce Admin plugin
155 |
156 | ## 3.0.7
157 | Fixed
158 | - Update php-bitpay-lib
159 | - Fix misleading error messages
160 | - Fix bug on some format of orderId
161 |
162 | = 3.0.6 =
163 | Fixed
164 | - Fix: Invalid code 0 during pairing on some install
165 |
166 | = 3.0.5 =
167 | Added:
168 | - Pass tax information to BTCPay Server
169 |
170 | = 3.0.4 =
171 | Fixed:
172 | - Fix JS Error on pairing mechanism
173 | Added:
174 | - Ensure compatibility with Wordpress 5
175 |
176 | = 3.0.3 =
177 | Fixed:
178 | - Remove legacy currency decimal precision checks
179 |
180 | = 3.0.2 =
181 | Fixed:
182 | - Fix float decimal issue
183 | - Make migrator pull from versions before 3.0.1 not 3.1
184 |
185 | = 3.0.1 =
186 | Changed:
187 | - When upgrading from any version smaller than 3.1 and settings are not set, attempt to load older version. Also display a warning prompt in plugins page after it has been activated to double check settings.
188 |
189 | = 3.0 =
190 | Changed:
191 | - Rebrand to be properly BTCPay labelled
192 | - Revert to using original Bitpay php lib and used Customnet for btcpay host urls
193 | - Update default order states to more reasonable values
194 | - Prepare plugin for Wordpress Plugin Repository
195 |
196 | =2.2.24 =
197 | Fixed
198 | - Bug: In some circumstances the auto update might crash the wordpress dashboard
199 |
200 | = 2.2.23 =
201 | Fixed
202 | - Setting `Keep store level settings` to `transaction speed` would still override store\'s setting
203 | Added
204 | - Add `low-medium` transaction speed
205 |
206 | = 2.2.22 =
207 | Fixed
208 | - Fix crash on some stores `Cannot use object of type stdClass as array in...` on the dashboard
209 |
210 | = 2.2.21 =
211 | Added
212 | - Add `event_invoice_expiredPaidPartial` handling
213 |
214 | = 2.2.20 =
215 | Fixed
216 | - Do not crash plugin page if update detection fails, be more resilient
217 |
218 | = 2.2.19 =
219 | Fixed
220 | - Ignore IPN if another payment method for the order has been chosen (#2)
221 | - Can detect new update in plugin page
222 |
223 | = 2.2.18 =
224 | Fixed
225 | - Ignore IPN if another payment method for the order has been chosen (#2)
226 |
227 | = 2.2.17 =
228 | Fixed
229 | - Fix a race condition if process_payment called twice
230 | - Can decide to ignore a BTCPay event
231 |
232 | = 2.2.16 =
233 | Fixed
234 | - Handle \'expired\' IPN
235 | - Handle \'invoice_paidAfterExpiration\' IPN event
236 |
237 | = Earlier versions =
238 | For the changelog of earlier versions, please refer to https://github.com/btcpayserver/woocommerce-plugin/releases
239 |
--------------------------------------------------------------------------------
/src/class-wc-gateway-btcpay.php:
--------------------------------------------------------------------------------
1 | id = 'btcpay';
105 | $this->icon = plugin_dir_url(__FILE__).'assets/img/icon.png';
106 | $this->has_fields = false;
107 | $this->order_button_text = __('Proceed to BTCPay', 'btcpay-for-woocommerce');
108 | $this->method_title = 'BTCPay';
109 | $this->method_description = 'BTCPay allows you to accept bitcoin payments on your WooCommerce store.';
110 |
111 | // Load the settings.
112 | $this->init_form_fields();
113 | $this->init_settings();
114 |
115 | // Define user set variables
116 | $this->title = $this->get_option('title');
117 | $this->description = $this->get_option('description');
118 | $this->order_states = $this->get_option('order_states');
119 | $this->debug = 'yes' === $this->get_option('debug', 'no');
120 |
121 | // Define BitPay settings
122 | $this->api_key = get_option('woocommerce_btcpay_key');
123 | $this->api_pub = get_option('woocommerce_btcpay_pub');
124 | $this->api_sin = get_option('woocommerce_btcpay_sin');
125 | $this->api_token = get_option('woocommerce_btcpay_token');
126 | $this->api_token_label = get_option('woocommerce_btcpay_label');
127 | $this->api_url = get_option('woocommerce_btcpay_url');
128 |
129 | // Define debugging & informational settings
130 | $this->debug_php_version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
131 | $this->debug_plugin_version = constant("BTCPAY_VERSION");
132 |
133 | $this->log('BTCPay Woocommerce payment plugin object constructor called. Plugin is v' . $this->debug_plugin_version . ' and server is PHP v' . $this->debug_php_version);
134 | $this->log(' [Info] $this->api_key = ' . $this->api_key);
135 | $this->log(' [Info] $this->api_pub = ' . $this->api_pub);
136 | $this->log(' [Info] $this->api_sin = ' . $this->api_sin);
137 | $this->log(' [Info] $this->api_token = ' . $this->api_token);
138 | $this->log(' [Info] $this->api_token_label = ' . $this->api_token_label);
139 | $this->log(' [Info] $this->api_url = ' . $this->api_url);
140 |
141 | // Process Credentials
142 | if (false === empty($this->api_key)) {
143 | try {
144 | $this->api_key = $this->btcpay_decrypt($this->api_key);
145 |
146 | if (false === empty($this->api_key)) {
147 | $this->log(' [Info] Private Key decrypted successfully.');
148 | } else {
149 | $this->log(' [Error] Private Key decrypted successfully BUT the value itself is null or empty!');
150 | }
151 | } catch (\Exception $e) {
152 | $this->log(' [Error] Private Key corrupt. Message is: ' . $e->getMessage());
153 | }
154 | } else {
155 |
156 | }
157 |
158 | if (false === empty($this->api_pub)) {
159 | try {
160 | $this->api_pub = $this->btcpay_decrypt($this->api_pub);
161 |
162 | if (false === empty($this->api_pub)) {
163 | $this->log(' [Info] Public Key decrypted successfully.');
164 | } else {
165 | $this->log(' [Error] Public Key decrypted successfully BUT the value itself is null or empty!');
166 | }
167 | } catch (\Exception $e) {
168 | $this->log(' [Error] Public Key corrupt. Message is: ' . $e->getMessage());
169 | }
170 | }
171 |
172 | if (false === empty($this->api_token)) {
173 | try {
174 | $this->api_token = $this->btcpay_decrypt($this->api_token);
175 |
176 | if (true === isset($this->api_token) && false === empty($this->api_token)) {
177 | $this->log(' [Info] API Token decrypted successfully.');
178 | } else {
179 | $this->log(' [Error] API Token decrypted successfully BUT the value itself is null or empty!');
180 | }
181 | } catch (\Exception $e) {
182 | $this->log(' [Error] API Token corrupt. Message is: ' . $e->getMessage());
183 | }
184 | }
185 |
186 | // Check API Credentials
187 | if (!($this->api_key instanceof \Bitpay\PrivateKey)) {
188 | $this->api_key = null;
189 | $this->log(' [Error] The API Key was NOT an instance of PrivateKey! Instead, it appears to be a ' . gettype($this->api_key) . ' value.');
190 | }
191 |
192 | if (!($this->api_pub instanceof \Bitpay\PublicKey)) {
193 | $this->api_pub = null;
194 | $this->log(' [Error] The Public Key was NOT an instance of PublicKey! Instead, it appears to be a ' . gettype($this->api_pub) . ' value.');
195 | }
196 |
197 | if (!($this->api_token instanceof \Bitpay\Token)) {
198 | $this->api_token = null;
199 | $this->log(' [Error] The API Token was NOT an instance of Token! Instead, it appears to be a ' . gettype($this->api_token) . ' value.');
200 | }
201 |
202 | $this->transaction_speed = $this->get_option('transaction_speed');
203 | $this->log(' [Info] Transaction speed is now set to: ' . $this->transaction_speed);
204 |
205 | // Actions
206 | add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
207 | add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'save_order_states'));
208 |
209 | // Valid for use and IPN Callback
210 | if (false === $this->is_valid_for_use()) {
211 | $this->enabled = 'no';
212 | $this->log(' [Info] The plugin is NOT valid for use!');
213 | } else {
214 | $this->enabled = 'yes';
215 | $this->log(' [Info] The plugin is ok to use.');
216 | add_action('woocommerce_api_wc_gateway_btcpay', array($this, 'ipn_callback'));
217 | }
218 |
219 | // Additional token initialization.
220 | if (btcpay_get_additional_tokens()) {
221 | $this->initialize_additional_tokens();
222 | }
223 | $this->is_initialized = true;
224 | }
225 |
226 | /**
227 | * Initializes additional tokens if any configured.
228 | */
229 | public function initialize_additional_tokens() {
230 | if ( $additional_tokens = btcpay_get_additional_tokens() ) {
231 | foreach ( $additional_tokens as $token ) {
232 |
233 | if ( ! class_exists( $token['classname'] ) ) {
234 | // Build the class structure.
235 | $classcode = "class {$token['classname']} extends WC_Gateway_BtcPay { ";
236 | $classcode .= "public \$token_mode;";
237 | $classcode .= "public \$token_symbol;";
238 | $classcode .= "public function __construct() { ";
239 | $classcode .= "parent::__construct();";
240 | $classcode .= "\$this->id = 'btcpay_{$token['symbol']}';";
241 | $classcode .= "\$this->method_title = 'BTCPay Asset: {$token['symbol']}';";
242 | $classcode .= "\$this->method_description = 'This is an additional asset managed by BTCPay.';";
243 | $classcode .= "\$this->title = '{$token['name']}';";
244 | $classcode .= "\$this->token_mode = '{$token['mode']}';";
245 | $classcode .= "\$this->token_symbol = '{$token['symbol']}';";
246 | $classcode .= "\$this->icon = '{$token['icon']}';";
247 | $classcode .= "\$this->init_settings();";
248 | $classcode .= "}";
249 | $classcode .= "public function ipn_callback() { ";
250 | $classcode .= "return;";
251 | $classcode .= "}";
252 | $classcode .= "}";
253 |
254 | // Initialize it on the fly.
255 | eval( $classcode );
256 | }
257 | }
258 | }
259 | }
260 |
261 | public function is_btcpay_payment_method($order)
262 | {
263 | $actualMethod = '';
264 | if (method_exists($order, 'get_payment_method')) {
265 | $actualMethod = $order->get_payment_method();
266 | } else {
267 | $actualMethod = get_post_meta( $order->get_id(), '_payment_method', true );
268 | }
269 |
270 | return (false !== strpos($actualMethod, 'btcpay'));
271 | }
272 |
273 | public function __destruct()
274 | {
275 | }
276 |
277 | public function is_valid_for_use()
278 | {
279 | // Check that API credentials are set
280 | if (true === is_null($this->api_key) ||
281 | true === is_null($this->api_pub) ||
282 | true === is_null($this->api_sin) ||
283 | true === is_null($this->api_token))
284 | {
285 | return false;
286 | }
287 |
288 | // Ensure the currency is supported by BitPay
289 | try {
290 | $currency = new \Bitpay\CurrencyUnrestricted(get_woocommerce_currency());
291 |
292 | if (false === isset($currency) || true === empty($currency)) {
293 | $this->log(' [Error] The BTCPay payment plugin was called to check if it was valid for use but could not instantiate a currency object.');
294 | throw new \Exception('The BTCPay payment plugin was called to check if it was valid for use but could not instantiate a currency object. Cannot continue!');
295 | }
296 | } catch (\Exception $e) {
297 | $this->log(' [Error] In is_valid_for_use: ' . $e->getMessage());
298 | return false;
299 | }
300 |
301 | $this->log(' [Info] Plugin is valid for use.');
302 |
303 | return true;
304 | }
305 |
306 | /**
307 | * Initialise Gateway Settings Form Fields
308 | */
309 | public function init_form_fields()
310 | {
311 | $this->log(' [Info] Entered init_form_fields()...');
312 | $log_file = 'btcpay-' . sanitize_file_name( wp_hash( 'btcpay' ) ) . '-log';
313 | $logs_href = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wc-status&tab=logs&log_file=' . $log_file;
314 |
315 | $this->form_fields = array(
316 | 'title' => array(
317 | 'title' => __('Title', 'btcpay-for-woocommerce'),
318 | 'type' => 'text',
319 | 'description' => __('Controls the name of this payment method as displayed to the customer during checkout.', 'btcpay-for-woocommerce'),
320 | 'default' => __('Bitcoin', 'btcpay-for-woocommerce'),
321 | 'desc_tip' => true,
322 | ),
323 | 'description' => array(
324 | 'title' => __('Customer Message', 'btcpay-for-woocommerce'),
325 | 'type' => 'textarea',
326 | 'description' => __('Message to explain how the customer will be paying for the purchase.', 'btcpay-for-woocommerce'),
327 | 'default' => 'You will be redirected to BTCPay to complete your purchase.',
328 | 'desc_tip' => true,
329 | ),
330 | 'api_token' => array(
331 | 'type' => 'api_token'
332 | ),
333 | 'transaction_speed' => array(
334 | 'title' => __('Invoice pass to "confirmed" state after', 'btcpay-for-woocommerce'),
335 | 'type' => 'select',
336 | 'description' => 'An invoice becomes confirmed after the payment has...',
337 | 'options' => array(
338 | 'default' => 'Keep store level configuration',
339 | 'high' => '0 confirmation on-chain',
340 | 'medium' => '1 confirmation on-chain',
341 | 'low-medium' => '2 confirmations on-chain',
342 | 'low' => '6 confirmations on-chain',
343 | ),
344 | 'default' => 'default',
345 | 'desc_tip' => true,
346 | ),
347 | 'order_states' => array(
348 | 'type' => 'order_states'
349 | ),
350 | 'debug' => array(
351 | 'title' => __('Debug Log', 'btcpay-for-woocommerce'),
352 | 'type' => 'checkbox',
353 | 'label' => sprintf(__('Enable logging View Logs', 'btcpay-for-woocommerce'), $logs_href),
354 | 'default' => 'no',
355 | 'description' => sprintf(__('Log BTCPay events, such as IPN requests, inside %s', 'btcpay-for-woocommerce'), wc_get_log_file_path('btcpay')),
356 | 'desc_tip' => true,
357 | ),
358 | 'notification_url' => array(
359 | 'title' => __('Notification URL', 'btcpay-for-woocommerce'),
360 | 'type' => 'url',
361 | 'description' => __('BTCPay will send IPNs for orders to this URL with the BTCPay invoice data', 'btcpay-for-woocommerce'),
362 | 'default' => '',
363 | 'placeholder' => WC()->api_request_url('WC_Gateway_BtcPay'),
364 | 'desc_tip' => true,
365 | ),
366 | 'redirect_url' => array(
367 | 'title' => __('Redirect URL', 'btcpay-for-woocommerce'),
368 | 'type' => 'url',
369 | 'description' => __('After paying the BTCPay invoice, users will be redirected back to this URL', 'btcpay-for-woocommerce'),
370 | 'default' => '',
371 | 'placeholder' => $this->get_return_url(),
372 | 'desc_tip' => true,
373 | ),
374 | 'additional_tokens' => array(
375 | 'title' => __('Additional token configuration', 'btcpay-for-woocommerce'),
376 | 'type' => 'textarea',
377 | 'description' => __('You can configure additional tokens here, one per line. e.g. "HAT;Hat Token;promotion" See documentation for details. Each one will be available as their own payment method.', 'btcpay-for-woocommerce'),
378 | 'default' => '',
379 | 'desc_tip' => true,
380 | ),
381 | 'additional_tokens_limit_payment' => array(
382 | 'title' => __('Additional tokens: Enforce payment tokens', 'btcpay-for-woocommerce'),
383 | 'type' => 'checkbox',
384 | 'label' => __('Limit default payment methods to listed "payment" tokens.', 'btcpay-for-woocommerce'),
385 | 'default' => 'no',
386 | 'value' => 'yes',
387 | 'description' => __('This will override the default btcpay payment method (defaults to all supported by BTCPay Server) and enforce to tokens of type "payment". This is useful if you want full control on what is available on BTCPay Server payment page.', 'btcpay-for-woocommerce'),
388 | 'desc_tip' => true,
389 | ),
390 | 'support_details' => array(
391 | 'title' => __( 'Plugin & Support Information', 'btcpay' ),
392 | 'type' => 'title',
393 | 'description' => sprintf(__('This plugin version is %s and your PHP version is %s. If you need assistance, please come on our chat https://chat.btcpayserver.org. Thank you for using BTCPay!', 'btcpay-for-woocommerce'), constant("BTCPAY_VERSION"), PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION),
394 | ),
395 | );
396 |
397 | $this->log(' [Info] Initialized form fields: ' . var_export($this->form_fields, true));
398 | $this->log(' [Info] Leaving init_form_fields()...');
399 | }
400 |
401 | /**
402 | * HTML output for form field type `api_token`
403 | */
404 | public function generate_api_token_html()
405 | {
406 | $this->log(' [Info] Entered generate_api_token_html()...');
407 |
408 | ob_start();
409 |
410 | // TODO: CSS Imports aren't optimal, but neither is this. Maybe include the css to be css-minimized?
411 | wp_enqueue_style('font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
412 | wp_enqueue_style('btcpay-token', plugins_url('assets/css/style.css', __FILE__));
413 | wp_enqueue_script('btcpay-pairing', plugins_url('assets/js/pairing.js', __FILE__), array('jquery'), null, true);
414 | wp_localize_script( 'btcpay-pairing', 'BtcPayAjax', array(
415 | 'ajaxurl' => admin_url( 'admin-ajax.php' ),
416 | 'pairNonce' => wp_create_nonce( 'btcpay-pair-nonce' ),
417 | 'revokeNonce' => wp_create_nonce( 'btcpay-revoke-nonce' )
418 | )
419 | );
420 |
421 | $pairing_form = file_get_contents(plugin_dir_path(__FILE__).'templates/pairing.tpl');
422 | $token_format = file_get_contents(plugin_dir_path(__FILE__).'templates/token.tpl');
423 | ?>
424 | | 492 | | 493 | 514 | | 515 |
|---|
The BTCPay Plugin for Woocoomerce has been updated from a 2.x version! 1807 | We have attempted to migrate your settings. Please double check them 1808 | here'?>. 1809 | If you don't see pairing data in your setting, make sure to pair your store again.
1810 |