Compare commits

..

25 Commits

Author SHA1 Message Date
ndeet
11efc8c117 Bump release.
Some checks failed
Build release artifact. / Build release (release) Has been cancelled
2025-09-08 15:52:27 +02:00
ndeet
d0ced96f5d Adding better logging for debugging user problems. 2025-09-08 15:51:27 +02:00
ndeet
806a5dda5a Fix version information.
Some checks failed
Build release artifact. / Build release (release) Has been cancelled
2025-09-01 21:17:09 +02:00
ndeet
cacf376ac1 Cleanup docs.
Some checks failed
Build release artifact. / Build release (release) Has been cancelled
2025-09-01 19:39:33 +02:00
ndeet
6556bd3d4f
Merge pull request #19 from ndeet/fix202508
Fix settings form not saving anymore
2025-09-01 19:17:39 +02:00
ndeet
db07ff1776 Make whmcs order confirmation page default redirect url. 2025-09-01 19:16:15 +02:00
ndeet
dd6a7f75f5 Fix bug preventing settings form form saving, cleanup and describe settings. 2025-09-01 19:15:53 +02:00
ndeet
60e51dbeaa
Revise BTCPay Server setup instructions in GUIDE.md 2025-09-01 18:21:45 +02:00
ndeet
d8d02b4684
Merge pull request #12 from g00g1/master
Added Tor support
2023-09-26 23:56:41 +02:00
Serg
e924de4af2 fix trailing slash issue
prevents sceario when gateway btcpayUrl was configured with trailing
slash and btcpayUrlTor without traling slash the url ended up like
example.onioni/INVOICEID instead of example.onion/i/INVOICEID
2023-09-26 12:01:25 +00:00
Serg
a1d66bf1c5 added tor support 2023-09-25 09:48:22 +00:00
Andreas Tasch
3affcaef25
Merge pull request #7 from ndeet/make-it-work
Make it work with recent WHMCS versions
2022-10-23 22:15:16 +02:00
Andreas Tasch
ee03301d51 Make sure url param does not get overridden by defaults; improving error output. 2022-10-22 22:48:18 +02:00
Andreas Tasch
29b7f30dea Remove test credentials. 2022-10-22 15:23:34 +02:00
Andreas Tasch
9c66088b4e Rename files and folders to btcpay. 2022-10-22 15:22:53 +02:00
Andreas Tasch
7055e4dd5a Adding whmcs.json metadata and logo image. 2022-10-22 15:13:48 +02:00
Andreas Tasch
c26bf68f61 Pump version. 2022-10-22 13:37:14 +02:00
Andreas Tasch
fa693e8477 Adding path to only zip that. 2022-10-22 11:14:00 +02:00
Andreas Tasch
000321c70e Exclude LICENSE from archive. 2022-10-22 11:07:40 +02:00
Andreas Tasch
abd54f0a7c Get tag appended to archive. 2022-10-22 10:53:22 +02:00
Andreas Tasch
b1aca78e01 Works now with latest WHMCS versions. 2022-10-21 23:56:25 +02:00
Andrew Camilleri
e754f7d2b3
Update README.md 2019-11-29 18:53:32 +01:00
nicolas.dorier
a92715de72 Push Tag on build 2018-05-09 22:02:16 +09:00
nicolas.dorier
550e63bf06 build script 2018-04-29 22:22:30 +09:00
nicolas.dorier
39b99f5c8d Add BTCPay support 2018-04-29 21:54:53 +09:00
23 changed files with 285 additions and 814 deletions

35
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Build release artifact.
on:
release:
types: [ published ]
jobs:
tag:
name: Build release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
# Composer install not needed as long as we have the system/libraries/ directory committed.
#- name: Install Composer dependencies
# uses: php-actions/composer@v6
# with:
# dev: no
# php_version: 7.4
# php_extensions: bcmath
- name: Create release artifact.
uses: thedoctor0/zip-release@master
with:
type: 'zip'
filename: 'BTCPay-WHMCS-Plugin-${{ github.ref_name }}.zip'
path: 'modules/'
exclusions: '*.git* *.github* composer.* README.md GUIDE.md LICENSE'
- name: Upload artifact to release page.
uses: ncipollo/release-action@v1
with:
artifacts: 'BTCPay-WHMCS-Plugin-${{ github.ref_name }}.zip'
removeArtifacts: true
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@ -26,3 +26,4 @@
/vendor/
composer.lock
composer.phar
dist/

View File

@ -1,39 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2011-2015 BitPay
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
language: php
php:
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm
install:
- composer install
script: ./bin/phing -propertyfile build/travis.properties build-travis
cache:
directories:
- build/cache/
- vendor/
matrix:
fast_finish: true
allow_failures:
- php: hhvm

View File

@ -1,32 +0,0 @@
[1.1.3] - 19 April 2018
* Added redirectURL to config screen
[1.1.2] - 2 March 2018
* Removed support for PHP 5.3
* Ability to specify redirectURL (PR #47)
[1.1.1] - 23 January 2018
Improved logging, tested against WHMCS 7.4.2
[1.1.0] - April 2018
Compatibility with WHMCS 7.1
Previous changelog:
1
* Initial version, tested against WHMCS 4.5.2
2 (09/12)
* Updated to use new API key instead of SSL files. Tested against WHMCS 5.2.3.
3 (03/14)
* Added new HTTP header for version tracking.
4 (05/14)
* Fix to use server error handling.
5 (01/15)
* Fix for invalid URL issue #16.
6 (07/13)
* Updated to be compatible with both WHMCS versions 5 and 6

View File

@ -1,52 +1,61 @@
# Using the BitPay payment plugin for WHMCS
# Using the BTCPay Server payment plugin for WHMCS
## Prerequisites
* Last Version Tested: 7.4.2
You must have a BitPay merchant account to use this plugin. It's free and easy to [sign-up for a BitPay merchant account](https://bitpay.com/start).
- PHP version 8.1 or newer, lower versions may work but are not maintained
- The curl, gd, intl, json, gmp (or bcmath) and mbstring PHP extensions are available
- WHMCS ([Download and installation instructions](https://download.whmcs.com/))
- You have a BTCPay Server version 1.3.0 or later, either [self-hosted](https://docs.btcpayserver.org/Deployment/) or [hosted by a third-party](https://docs.btcpayserver.org/Deployment/ThirdPartyHosting/)
- [You've a registered account on the instance](https://docs.btcpayserver.org/RegisterAccount/)
- [You've a BTCPay store on the instance](https://docs.btcpayserver.org/CreateStore/)
- [You've a wallet connected to your store](https://docs.btcpayserver.org/WalletSetup/)
## Installation
Extract these files into the WHMCS directory on your webserver (parent directory of
modules/folder).
1. Download the latest release from the [releases page](https://github.com/btcpayserver/whmcs-plugin/releases). e.g. BTCPay-WHMCS-Plugin-v3.1.0.zip
2. Extract the .zip file which will result in a `modules/gateways/btcpay` directory
3. Copy those files into your WHMCS root directory or copy only the `btcpay` directory so it ends up in the `modules/gateways/` directory
4. Double check that you now have files in `PATH_TO_WHMCS/modules/gateways/btcpay/` directory
## Configuration
1. Take a moment to ensure that you have set your store's domain and the WHMCS System URL under **whmcs/admin > Setup > General Settings**.
2. Create a "Legacy API Key" in your BitPay merchant account dashboard:
* Log into https://bitpay.com with your account username/password.
### Step 1: On WHMCS
1. Navigate to **Apps & Integrations** in your admin dashboard.
2. Search for "BTCPay" and click on the result.
3. Click on "**Activate**" button to get to the configuration screen.
4. Head over to your BTCPay Server instance to create an API key.
### Step 2: On your BTCPay Server instance (open in a new tab/browser window)
1. Log in with your user.
2. Select the store you want to connect to. Make sure it has setup a wallet so you can receive payments.
3. Create a "Legacy API Key" on your BTCPay Server store account dashboard:
* On the left side of the screen, choose **Settings**.
* The menu will expand downward revealing a list of options. Choose the **Legacy API Keys** option.
* On the right side of the page, click on the grey **+ Add New API Key** button to instantly create a new one.
* Select and copy the entire string for the new API Key ID that you just created. It will look something like this: 43rp4rpa24d6Bz4BR44j8zL44PrU4npVv4DtJA4Kb8.
3. In the admin control panel, go to **Setup > Payment Gateways**, select **Bit-pay** in the list of modules and click **Activate**.
* If you can't find the BitPay plugin in the list of payment gateways -or- in the WHMCS app store, then you may clone this repo and copy modules/gateways into your <whmcs root>/modules/gateways/.
4. Paste the API Key ID string that you created and copied from step 2.
5. Choose a transaction speed. This setting determines how quickly you will receive a payment confirmation from BitPay after an invoice is paid by a customer.
* High: A confirmation is sent instantly once the payment has been received by the gateway.
* Medium: A confirmation is sent after 1 block confirmation (~10 mins) by the bitcoin network.
* Select subnavigation entry **Access Tokens**.
* Below the "Legacy API Keys" headline click on the **Generate** button to instantly create a new one.
* Select and copy the entire string for the new API Key ID that you just created. It will look something like this: `43rp4rpa24d6Bz4BR44j8zL44PrU4npVv4DtJA4Kb8`.
### Step 3: Back on WHMCS
1. Make sure "**Show on Order Form" is checked.
2. Change "**Display Name**" to what you prefer e.g. "Bitcoin / Lightning Network payments"
3. Paste the api key that you created and copied from step 2 above in the field "**Legacy API Key**".
4. In "**BTCPay Server URL**" enter the domain from your own BTCPay Server instance (e.g. https://mainnet.demo.btcpayserver.org).
5. (optional) In "**BTCPay Server Tor URL**" you can enter the BTCPay Server's .onion address. Note: this will only work if your WHMCS is also reachable over Tor and your users use Tor Browser.
6. (optional) In "**Redirect URL after invoice**" you can set a custom URL where the customer gets redirected after successful payment. If not it will redirect to the invoice page.
7. Set "**Transaction Speed**" field. This setting determines how quickly you will receive a payment confirmation from BTCPay Server after an invoice is paid by a customer.
* High: A confirmation is sent instantly once the payment has been received by the gateway, means 0-conf, do not use.
* Medium: A confirmation is sent after 1 block confirmation (~10 mins) by the bitcoin network (**<== recommended setting**).
* Low: A confirmation is sent after the usual 6 block confirmations (~1 hour) by the bitcoin network.
6. If you see the **Convert To For Processing** option, choose a currency that is accepted by BitPay (e.g. BTC/USD/CAD). You can see a full list of our supported currencies here: [Bitcoin Exchange Rates](https://bitpay.com/bitcoin-exchange-rates).
7. If you see the option but such a currency does not appear here, or if don't see the option and you are currently accepting a currency that is not accepted by BitPay:
* Click **Save Changes**.
* Create an accepted currency (e.g. USD/BTC/CAD) by going to **Setup > Currencies**, filling out the form and clicking **Add Currency**.
* **NOTE:** You will have to update the conversion rate manually for BTC, so it's advisable here to choose your local currency over BTC since the BTC exchange rate update can be automated for your local currency.
* Return to **Setup > Payment Gateways** and choose this new currency for the "Convert To For Processing" setting.
8. Click **Save Changes**.
You're done!
Congrats, setup is done. Now test if the payment works.
## Usage
When a client chooses the BitPay payment method, they will be presented with an invoice showing a button they will have to click on in order to pay their order. Upon requesting to pay their order, the system takes the client to a full-screen bitpay.com invoice page where the client is presented with payment instructions. Once payment is received, a link is presented to the shopper that will return them to your website.
When a client chooses the BTCPay Server payment method, they will be presented the option to pay with Bitcoin via BTCPay Server. When clicking on "Complete order" button, they get redirected to a full-screen invoice page of your BTCPay Server where the client is presented with payment instructions. Once payment is received, they can click "Back to store" to return to your website (by default they will be redirected to the order confirmation page).
**NOTE:** Don't worry! A payment will automatically update your WHMCS store whether or not the customer returns to your website after they've paid the invoice.
**NOTE:** In case of on-chain payments that need to get included in a block your customer does not need to wait, the payment status will get updated automatically over a webhook and mark the order as paid, which will trigger the corresponding email confirming the payment.
In your WHMCS control panel, you can see the information associated with each order made via BitPay by choosing **Orders > Pending Orders**. This screen will tell you whether payment has been received by the BitPay servers. You can also view the details for any paid invoice inside your BitPay merchant dashboard under the **Payments** page.
In your WHMCS control panel, you can see the information associated with each order made via BTCPay Server by choosing **Orders > Pending Orders**. This screen will tell you whether payment has been received by the BTCPay Server instance. You can also view the details for any paid invoice inside your BTCPay store dashboard under the **Invoices** page.
**NOTE:** This extension does not provide a means of automatically pulling a current BTC exchange rate for presenting BTC prices to shoppers. If you want to have a BTC currency in your installation, you must update the exchange rate manually.
**NOTE:** This extension does not provide a means of automatically pulling a current BTC exchange rate for presenting BTC prices for your products to shoppers. This plugin only provides the means to accept payments in BTC and Lightning Network payments.

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2011-2018 BitPay
Copyright (c) 2011-2018 BitPay, 2019-2021 BTCPay Server
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,51 +1,45 @@
# Description
Bitcoin payment plugin for WHMCS using the bitpay.com service.
[![Build Status](https://travis-ci.org/bitpay/whmcs-plugin.svg?branch=master)](https://travis-ci.org/bitpay/whmcs-plugin)
Bitcoin payment plugin for WHMCS using the BTCPay Server.
## Quick Start Guide
To get up and running with our plugin quickly, see the GUIDE here: https://github.com/bitpay/whmcs-plugin/blob/master/GUIDE.md
To get up and running with our plugin quickly, see the GUIDE here: https://github.com/btcpayserver/whmcs-plugin/blob/master/GUIDE.md
## Support
**BitPay Support:**
* Last Version Tested: 7.4.2
* [GitHub Issues](https://github.com/bitpay/whmcs-plugin/issues)
* Open an issue if you are having issues with this plugin
* [Support](https://help.bitpay.com)
* BitPay merchant support documentation
* WHMCS version tested: v8.13
* [GitHub Issues](https://github.com/btcpayserver/whmcs-plugin/issues)
* Open an issue if you are having troubles with this plugin
**WHMCS Support:**
* [Homepage](https://www.whmcs.com/)
* [Documentation](http://docs.whmcs.com/Main_Page)
* [SupportForums](http://forum.whmcs.com/)
* [Documentation](https://docs.whmcs.com/)
* [SupportForums](https://whmcs.community/)
## Troubleshooting
0. 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.
1. 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.
2. 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/bitpay/whmcs-plugin/releases/latest) page for the latest.
3. If all else fails, contact us using one of the methods described in the Support section above.
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.
2. Verify that your web server is not blocking POST requests from servers it may not recognize. Double-check this on your firewall as well, if one is being used.
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/whmcs-plugin/releases/latest) page for the latest.
4. If all else fails, contact us using one of the methods described in the Support section above.
**TIP**: When contacting support it will help us is you provide:
**TIP**: When contacting support, it will help us if you provide:
* WHMCS and BitPay Plugin Version
* Any log files that will help
* WHMCS logs and Web server error logs
* Screen grabs of error message if applicable.
* WHMCS and BTCPay Server Plugin version
* PHP version used
* WHMCS logs and Web server error logs
* Screenshots of error messages
## Contribute
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/bitpay/whmcs-plugin/issues) and tell us about it.
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/whmcs-plugin/issues) and tell us about it.
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!
If you *are* a developer wanting to 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!
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 send us an email](mailto:integrations@bitpay.com).
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. This plugin is forked from the BitPay WHMCS plugin.
## License
Please refer to the [LICENSE](https://github.com/bitpay/whmcs-plugin/blob/master/LICENSE) file that came with this project.
Please refer to the [LICENSE](https://github.com/btcpayserver/whmcs-plugin/blob/master/LICENSE) file that came with this project.

200
build.xml
View File

@ -1,200 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* The MIT License (MIT)
*
* Copyright (c) 2011-2015 BitPay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-->
<project name="bitpay/build-script" default="build">
<!--
Default properties
-->
<property file="${project.basedir}/build/build.properties" />
<!--
Default build for running a build locally
-->
<target name="build" depends="prepare"
description="Runs a full build">
<phingcall target="lint" />
<phingcall target="phpunit" />
<parallel threadCount="5">
<phingcall target="phpcs" />
<phingcall target="phpmd" />
<phingcall target="phploc" />
<phingcall target="pdepend" />
<phingcall target="build-api-docs" />
</parallel>
</target>
<!--
Build API and other documentation
-->
<target name="build-api-docs" depends="prepare"
description="Generates API docs for the project">
<delete dir="${phpdoc.target}" verbose="true" />
<exec executable="${project.bindir}/phpdoc" passthru="true">
<arg value="--directory=${phpdoc.directory}" />
<arg value="--target=${phpdoc.target}" />
<arg line="--ignore=${phpdoc.ignore}" />
</exec>
</target>
<!--
Used to run a build on Travis CI
-->
<target name="build-travis" hidden="true"
description="Runs a build that is specific to the Travis CI environment">
<phingcall target="build" />
</target>
<!--
Generates documentation that can be uploaded to a web site and is meant
to be used elsewhere by the project.
-->
<target name="build-docs"
description="Generates documentation">
<fail message="Needs to be configured" />
</target>
<!--
Generates a distribution file that can then be used for uploading to
various plugin specific sites for users to download.
-->
<target name="build-dist"
description="Builds a distribution file">
<fail message="Needs to be configured" />
</target>
<!--
Cleans up and makes sure that the build is
clean
-->
<target name="clean" hidden="true">
<delete dir="build/docs" verbose="true" />
<delete dir="build/logs" verbose="true" />
</target>
<!--
Prepares the project for a build
-->
<target name="prepare" depends="clean" hidden="true">
<mkdir dir="build/cache" />
<mkdir dir="build/logs" />
</target>
<!--
Lint check all php files, this task should be updated for each
project so it only lint checks files specific for that project
-->
<target name="lint"
description="Check the syntax of PHP files">
<phplint cachefile="${project.basedir}/build/cache/phplint.cache">
<fileset dir="${project.basedir}/">
<include name="**/*.php"/>
<exclude name="**/build/**"/>
<exclude name="**/bin/**"/>
<exclude name="**/vendor/**"/>
</fileset>
</phplint>
</target>
<!--
phpunit - Runs phpunit with the phpunit.xml.dist file
http://phpunit.de/
-->
<target name="phpunit"
description="Runs unit tests">
<exec executable="${project.bindir}/phpunit" passthru="true">
<arg value="-c" />
<arg path="${phpunit.configuration}" />
</exec>
</target>
<!--
PHP Mess Detector
http://phpmd.org
-->
<target name="phpmd"
description="Runs PHP Mess Detector">
<delete file="${phpmd.report.file}" />
<exec executable="${project.bindir}/phpmd" passthru="true">
<arg path="${phpmd.source}" />
<arg value="${phpmd.report.format}" />
<arg value="${phpmd.ruleset}" />
<arg line="--reportfile ${phpmd.report.file}" />
<arg line="--exclude ${phpmd.exclude}" />
</exec>
</target>
<!--
PHP Lines of Code - Generates a CSV and XML log of how many lines
the project is.
https://github.com/sebastianbergmann/phploc
-->
<target name="phploc"
description="Calculates the size of the code base">
<delete file="${phploc.log.csv}" />
<delete file="${phploc.log.xml}" />
<exec executable="${project.basedir}/bin/phploc" passthru="true">
<arg line="--exclude=${phploc.exclude}" />
<arg value="--log-csv=${phploc.log.csv}" />
<arg value="--log-xml=${phploc.log.xml}" />
<arg path="${phploc.source}" />
</exec>
</target>
<!--
PHP Depend
http://pdepend.org/
-->
<target name="pdepend"
description="Generates some code metrics and pretty pictures">
<delete file="${pdepend.jdepend.xml}" />
<delete file="${pdepend.summary.xml}" />
<exec executable="${project.bindir}/pdepend" passthru="true">
<arg value="--jdepend-chart=${pdepend.jdepend.chart}" />
<arg value="--jdepend-xml=${pdepend.jdepend.xml}" />
<arg value="--overview-pyramid=${pdepend.overview.pyramid}" />
<arg value="--summary-xml=${pdepend.summary.xml}" />
<arg value="--ignore=${pdepend.ignore}" />
<arg path="${pdepend.source}" />
</exec>
</target>
<!--
PHP Code Sniffer - Makes sure the code meets standards, this
needs to be updated for each project
https://github.com/squizlabs/PHP_CodeSniffer
-->
<target name="phpcs"
description="Runs PHP Code Sniffer to make sure your code doesn't smell">
<delete file="${phpcs.report.xml}" />
<exec executable="${project.bindir}/phpcs" passthru="true">
<arg value="-p" /> <!-- Show progress of run -->
<arg value="--report-xml=${phpcs.report.xml}" />
<arg line="--standard=${phpcs.standard}" />
<arg line="--ignore=${phpcs.ignore}" />
<arg path="${phpcs.source}" />
</exec>
</target>
</project>

View File

@ -1,145 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2011-2015 BitPay
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
####
#
# This properties file is used to configure the entire build. The purpose of
# this file is so that it is easy to drop it into a project and change a few
# of these settings and have a build run successfully.
#
# NOTE: You may still need to take a look at and edit `phpunit.xml.dist`.
#
####
#
# Directory Configuration
#
# The main location of all the projects source code, this should be the only
# property that you need to change. Code can live in the root directory or it
# can live inside of it's own directory.
project.source=${project.basedir}
#project.source=${project.basedir}/src
# --- You shouldn't need to edit any of the below value ---
# Location of all executables, this is the location on the `bin-dir` that you
# have configured in `composer.json`. If you have not configured this in
# 1composer.json` the default is to put it in the `vendor` directory.
project.bindir=${project.basedir}/bin
#project.bindir=${project.basedir}/vendor/bin
# Where to put the build artifacts, cache, logs, docs, etc.
project.builddir=${project.basedir}/build
# Location of vendor directory created by composer.
project.vendordir=${project.basedir}/vendor
# build artifacts for code analysis
project.logsdir=${project.builddir}/logs
# Build artifacts that can be reused or updated, they do not need to be deleted
# every build. These would include charts and images.
project.cachedir=${project.builddir}/cache
# Location of generated documentation such as API and code coverage
project.docsdir=${project.builddir}/docs
#### directory ####
####
#
# phpunit configuration
#
# Directory that contains phpunit.xml or the phpunit.xml file itself
phpunit.configuration=${project.builddir}/phpunit.xml.dist
#### phpunit ####
####
#
# phpmd configuration
#
# php source code filename or directory. Can be a comma-separated string
phpmd.source=${project.source}
# report format, text, xml, or html
phpmd.report.format=xml
# ruleset filename or a comma-separated string of rulesetfilenames
phpmd.ruleset=${project.builddir}/rulesets/phpmd.xml
# send report output to this file
phpmd.report.file=${project.logsdir}/phpmd.xml
# comma-separated string of patterns that are used to ignore directories
phpmd.exclude=${project.bindir},${project.builddir},${project.vendordir},${project.basedir}/tests
#### phpmd ####
####
#
# phploc Configuration
#
# Source directory of project
phploc.source=${project.source}/
# Where to put the csv log
phploc.log.csv=${project.logsdir}/phploc.csv
# Location of xml log
phploc.log.xml=${project.logsdir}/phploc.xml
# Small hack to exclude multiple directories
phploc.exclude=vendor --exclude=build --exclude=bin --exclude=tests
#### phploc ####
####
#
# pdepend configuration
#
pdepend.source=${project.source}
pdepend.jdepend.chart=${project.cachedir}/jdepend_chart.svg
pdepend.jdepend.xml=${project.logsdir}/jdepend.xml
pdepend.overview.pyramid=${project.cachedir}/pyramid.svg
pdepend.summary.xml=${project.logsdir}/jdepend_summary.xml
pdepend.ignore=bin,build,vendor,tests
#### pdepend ####
####
#
# phpcs configuration
#
phpcs.source=${project.source}
phpcs.report.xml=${project.logsdir}/phpcs.xml
phpcs.standard=PSR1 --standard=PSR2
phpcs.ignore=vendor --ignore=bin --ignore=build --ignore=tests
#### phpcs ####
####
#
# phpdoc configuration
#
phpdoc.directory=${project.source}/
phpdoc.target=${project.docsdir}/api
phpdoc.ignore=vendor/,bin/,tests/
#### phpdoc ####

View File

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* The MIT License (MIT)
*
* Copyright (c) 2011-2015 BitPay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals = "false"
colors = "true"
verbose = "true"
>
<testsuites>
<testsuite name="BitPay Project Test Suite">
<directory>../tests/*Test.php</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory>../build</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-html" target="../build/docs/code-coverage" />
<log type="coverage-clover" target="../build/logs/clover.xml" />
</logging>
</phpunit>

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* The MIT License (MIT)
*
* Copyright (c) 2011-2015 BitPay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-->
<ruleset name="PHPMD Ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Custom phpmd ruleset to be used with BitPay projects.
</description>
<!-- Import -->
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/unusedcode.xml" />
</ruleset>

View File

@ -1,145 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2011-2015 BitPay
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
####
#
# This properties file is used to configure the entire build. The purpose of
# this file is so that it is easy to drop it into a project and change a few
# of these settings and have a build run successfully.
#
# NOTE: You may still need to take a look at and edit `phpunit.xml.dist`.
#
####
#
# Directory Configuration
#
# The main location of all the projects source code, this should be the only
# property that you need to change. Code can live in the root directory or it
# can live inside of it's own directory.
project.source=${project.basedir}
#project.source=${project.basedir}/src
# --- You shouldn't need to edit any of the below value ---
# Location of all executables, this is the location on the `bin-dir` that you
# have configured in `composer.json`. If you have not configured this in
# 1composer.json` the default is to put it in the `vendor` directory.
project.bindir=${project.basedir}/bin
#project.bindir=${project.basedir}/vendor/bin
# Where to put the build artifacts, cache, logs, docs, etc.
project.builddir=${project.basedir}/build
# Location of vendor directory created by composer.
project.vendordir=${project.basedir}/vendor
# build artifacts for code analysis
project.logsdir=${project.builddir}/logs
# Build artifacts that can be reused or updated, they do not need to be deleted
# every build. These would include charts and images.
project.cachedir=${project.builddir}/cache
# Location of generated documentation such as API and code coverage
project.docsdir=${project.builddir}/docs
#### directory ####
####
#
# phpunit configuration
#
# Directory that contains phpunit.xml or the phpunit.xml file itself
phpunit.configuration=${project.builddir}/phpunit.xml.dist
#### phpunit ####
####
#
# phpmd configuration
#
# php source code filename or directory. Can be a comma-separated string
phpmd.source=${project.source}
# report format, text, xml, or html
phpmd.report.format=xml
# ruleset filename or a comma-separated string of rulesetfilenames
phpmd.ruleset=${project.builddir}/rulesets/phpmd.xml
# send report output to this file
phpmd.report.file=${project.logsdir}/phpmd.xml
# comma-separated string of patterns that are used to ignore directories
phpmd.exclude=${project.bindir},${project.builddir},${project.vendordir},${project.basedir}/tests
#### phpmd ####
####
#
# phploc Configuration
#
# Source directory of project
phploc.source=${project.source}/
# Where to put the csv log
phploc.log.csv=${project.logsdir}/phploc.csv
# Location of xml log
phploc.log.xml=${project.logsdir}/phploc.xml
# Small hack to exclude multiple directories
phploc.exclude=vendor --exclude=build --exclude=bin --exclude=tests
#### phploc ####
####
#
# pdepend configuration
#
pdepend.source=${project.source}
pdepend.jdepend.chart=${project.cachedir}/jdepend_chart.svg
pdepend.jdepend.xml=${project.logsdir}/jdepend.xml
pdepend.overview.pyramid=${project.cachedir}/pyramid.svg
pdepend.summary.xml=${project.logsdir}/jdepend_summary.xml
pdepend.ignore=bin,build,vendor,tests
#### pdepend ####
####
#
# phpcs configuration
#
phpcs.source=${project.source}
phpcs.report.xml=${project.logsdir}/phpcs.xml
phpcs.standard=PSR1 --standard=PSR2
phpcs.ignore=vendor --ignore=bin --ignore=build --ignore=tests
#### phpcs ####
####
#
# phpdoc configuration
#
phpdoc.directory=${project.source}/
phpdoc.target=${project.docsdir}/api
phpdoc.ignore=vendor/,bin/,tests/
#### phpdoc ####

View File

@ -1,25 +1,23 @@
{
"name": "bitpay/whmcs",
"description": "BitPay payment plugin for WHMCS",
"name": "btcpayserver/whmcs",
"description": "BTCPay Server payment plugin for WHMCS",
"type": "whmcs-plugin",
"keywords": ["whmcs","plugin","payment","ecommerce","bitcoin","bitpay"],
"homepage": "https://github.com/bitpay/whmcs-plugin",
"keywords": ["whmcs","plugin","payment","ecommerce","bitcoin","btcpay","btcpayserver"],
"homepage": "https://github.com/btcpayserver/whmcs-plugin",
"license": "MIT",
"support": {
"email": "support@bitpay.com",
"issues": "https://github.com/bitpay/whmcs-plugin/issues",
"source": "https://github.com/bitpay/whmcs-plugin"
"email": "support@btcpayserver.org",
"issues": "https://github.com/btcpayserver/whmcs-plugin/issues",
"source": "https://github.com/btcpayserver/whmcs-plugin"
},
"minimum-stability": "stable",
"authors": [
{
"name": "BitPay Integrations Development Team",
"email": "integrations@bitpay.com",
"homepage": "https://bitpay.com/integrations"
"name": "BTCPay Server Integrations Development Team"
}
],
"require": {
"php": ">=5.4",
"php": ">=7.4",
"ext-curl": "*",
"ext-json": "*",
"composer/installers": "~1.0"

View File

@ -2,7 +2,7 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2011-2018 BitPay
* Copyright (c) 2011-2018 BitPay, BTCPay server (c) 2019-2022
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -23,36 +23,55 @@
* THE SOFTWARE.
*/
function btcpay_MetaData()
{
return [
'DisplayName' => 'BTCPay Server (legacy API)',
'failedEmail' => 'Credit Card Payment Failed',
'successEmail' => 'BTCPay Payment Success',
'pendingEmail' => 'BTCPay Payment Pending',
'APIVersion' => '1.1',
];
}
/**
* Returns configuration options array.
*
* @return array
*/
function bitpay_config()
function btcpay_config()
{
$configarray = array(
"FriendlyName" => array(
"Type" => "System",
"Value"=>"BitPay"
"Value" => "Bitcoin payments via BTCPay Server"
),
'apiKey' => array(
'FriendlyName' => 'Legacy API Key from your bitpay.com merchant account.',
'Type' => 'text'
'FriendlyName' => 'Legacy API Key',
'Type' => 'text',
'Description' => 'Your legacy API key. You can create a new one in your BTCPay Server store settings > Access Tokens.',
),
'network' => array(
'FriendlyName' => 'Select if this key is from bitpay.com or test.bitpay.com.',
'Type' => 'dropdown',
'Options' => 'live,test',
'btcpayUrl' => array(
'FriendlyName' => 'BTCPay Server URL',
'Type' => 'text',
'Description' => 'The URL of your BTCPay Server instance, e.g., https://btcpay.example.com.',
),
'btcpayUrlTor' => array(
'FriendlyName' => 'BTCPay Server Tor URL (optional)',
'Type' => 'text',
'Description' => 'The Tor URL of your BTCPay Server instance. This is optional and only used if WHMCS is accessed via a .onion domain.',
),
'redirectURL' => array(
'FriendlyName' => 'Redirect URL after BitPay invoice',
'FriendlyName' => 'Redirect URL (optional)',
'Type' => 'text',
'Value' => isset($_POST['redirectURL']) ? $_POST['redirectURL'] : $_POST['systemURL']
'Description' => 'URL to redirect to after payment. Leave blank to use the default WHMCS order confirmation page.',
),
'transactionSpeed' => array(
'FriendlyName' => 'Transaction Speed',
'Type' => 'dropdown',
'Options' => 'low,medium,high'
'Options' => 'low,medium,high',
'Default' => 'medium',
'Description' => 'The transaction speed to use for the invoice. Medium is recommended. See docs for a detailed explanation.',
),
);
@ -65,10 +84,10 @@ function bitpay_config()
* @param array $params
* @return string
*/
function bitpay_link($params)
function btcpay_link($params)
{
if (false === isset($params) || true === empty($params)) {
die('[ERROR] In modules/gateways/bitpay.php::bitpay_link() function: Missing or invalid $params data.');
die('[ERROR] In modules/gateways/btcpay.php::btcpay_link() function: Missing or invalid $params data.');
}
// Invoice Variables
@ -86,12 +105,22 @@ function bitpay_link($params)
$country = $params['clientdetails']['country'];
$phone = $params['clientdetails']['phonenumber'];
// Tor support
$parsedurl = parse_url($params['systemurl']);
$is_tor_enabled = preg_match("/\.onion$/", $_SERVER['HTTP_HOST']) && $params['btcpayUrlTor'] != '';
if (is_array($parsedurl) && $is_tor_enabled) {
$systemtor = "http://{$_SERVER['HTTP_HOST']}" . $parsedurl['path'];
} else {
$systemtor = "";
}
// System Variables
$systemurl = $params['systemurl'];
$systemurl = $systemtor != '' ? $systemtor : $params['systemurl'];
$post = array(
'invoiceId' => $invoiceid,
'systemURL' => $systemurl,
'ipnURL' => $params['systemurl'] . '/modules/gateways/callback/btcpay.php',
'buyerName' => $firstname . ' ' . $lastname,
'buyerAddress1' => $address1,
'buyerAddress2' => $address2,
@ -102,7 +131,7 @@ function bitpay_link($params)
'buyerPhone' => $phone,
);
$form = '<form action="' . $systemurl . '/modules/gateways/bit-pay/createinvoice.php" method="POST">';
$form = '<form action="' . $systemurl . '/modules/gateways/btcpay/createinvoice.php" method="POST">';
foreach ($post as $key => $value) {
$form .= '<input type="hidden" name="' . $key . '" value = "' . $value . '" />';

View File

@ -2,7 +2,7 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2011-2018 BitPay
* Copyright (c) 2011-2018 BitPay, BTCPay server (c) 2019-2022
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -43,6 +43,7 @@ function bpLog($contents)
function bpCurl($url, $apiKey, $post = false)
{
global $bpOptions;
global $version;
$curl = curl_init($url);
$length = 0;
@ -58,7 +59,7 @@ function bpCurl($url, $apiKey, $post = false)
'Content-Type: application/json',
'Content-Length: ' . $length,
'Authorization: Basic ' . $uname,
'X-BitPay-Plugin-Info: whmcs'. $version,
'X-BitPay-Plugin-Info: whmcs '. $version,
);
curl_setopt($curl, CURLOPT_PORT, 443);
@ -72,16 +73,30 @@ function bpCurl($url, $apiKey, $post = false)
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
$responseString = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$curlError = curl_error($curl);
$curlErrno = curl_errno($curl);
if ($responseString == false) {
$response = array('error' => curl_error($curl));
bpLog('[ERROR] In modules/gateways/bitpay/bp_lib.php::bpCurl(): Invalid response received: ' . var_export($response, true));
if ($responseString === false) {
$response = array('error' => 'curl errno: ' . $curlErrno . ', error: ' . $curlError);
bpLog('[ERROR] In modules/gateways/btcpay/bp_lib.php::bpCurl(): cURL request failed: ' . var_export($response, true));
} else {
$response = json_decode($responseString, true);
if (!$response) {
bpLog('[ERROR] In modules/gateways/bitpay/bp_lib.php::bpCurl(): Invalid response received: ' . var_export($responseString, true));
$response = array('error' => 'invalid json: ' . $responseString);
if ($response === null && json_last_error() !== JSON_ERROR_NONE) {
$jsonError = json_last_error_msg();
$responsePreview = empty($responseString) ? '[EMPTY RESPONSE]' : (strlen($responseString) > 200 ? substr($responseString, 0, 200) . '...' : $responseString);
bpLog('[ERROR] In modules/gateways/btcpay/bp_lib.php::bpCurl(): JSON decode failed. HTTP Code: ' . $httpCode . ', JSON Error: ' . $jsonError . ', cURL errno: ' . $curlErrno . ', Response: ' . var_export($responsePreview, true));
$errorMsg = 'JSON decode failed (HTTP ' . $httpCode . '): ' . $jsonError;
if (!empty($responseString)) {
$errorMsg .= '. Response: ' . $responsePreview;
} else {
$errorMsg .= '. Empty response received from BTCPay Server.';
}
$response = array('error' => $errorMsg);
}
}
@ -90,6 +105,17 @@ function bpCurl($url, $apiKey, $post = false)
return $response;
}
function getFullUri($baseUri, $path)
{
$uriNormalized = rtrim($baseUri, '/');
$pathNormalized = ltrim($path, '/');
return sprintf(
'%s/%s',
$uriNormalized,
$pathNormalized
);
}
/**
* $orderId: Used to display an orderID to the buyer. In the account summary view, this value is used to
* identify a ledger entry if present.
@ -131,11 +157,7 @@ function bpCreateInvoice($orderId, $price, $posData, $options = array())
$options['orderID'] = $orderId;
$options['price'] = $price;
if ($options['network'] == 'test') {
$network = 'https://test.bitpay.com/api/invoice/';
} else {
$network = 'https://bitpay.com/api/invoice/';
}
$btcpayUrl = getFullUri($options['btcpayUrl'],"/invoices");
$postOptions = array('orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL',
'posData', 'price', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName',
@ -147,9 +169,9 @@ function bpCreateInvoice($orderId, $price, $posData, $options = array())
}
}
$post = json_encode($post);
$post = json_encode($post);
$response = bpCurl($network, $options['apiKey'], $post);
$response = bpCurl($btcpayUrl, $options['apiKey'], $post);
return $response;
}
@ -158,10 +180,10 @@ function bpCreateInvoice($orderId, $price, $posData, $options = array())
* Call from your notification handler to convert $_POST data to an object containing invoice data
*
* @param string $apiKey
* @param null $network
* @param null $btcpayUrl
* @return array
*/
function bpVerifyNotification($apiKey = false, $network = null)
function bpVerifyNotification($apiKey = false, $btcpayUrl = null)
{
global $bpOptions;
@ -188,7 +210,7 @@ function bpVerifyNotification($apiKey = false, $network = null)
$posData = json_decode($json['posData'], true);
if ($bpOptions['verifyPos'] and $posData['hash'] != crypt($posData['posData'], $apiKey)) {
return 'ERROR: authentication failed (bad hash)';
return 'ERROR: payload validation failed (bad hash)';
}
$json['posData'] = $posData['posData'];
@ -197,7 +219,7 @@ function bpVerifyNotification($apiKey = false, $network = null)
return 'Cannot find invoice ID';
}
return bpGetInvoice($json['id'], $apiKey, $network);
return bpGetInvoice($json['id'], $apiKey, $btcpayUrl);
}
/**
@ -205,10 +227,10 @@ function bpVerifyNotification($apiKey = false, $network = null)
*
* @param string $invoiceId
* @param string $apiKey
* @param string $network
* @param string $btcpayUrl
* @return array
*/
function bpGetInvoice($invoiceId, $apiKey = false, $network = null)
function bpGetInvoice($invoiceId, $apiKey = false, $btcpayUrl = null)
{
global $bpOptions;
@ -216,22 +238,22 @@ function bpGetInvoice($invoiceId, $apiKey = false, $network = null)
$apiKey = $bpOptions['apiKey'];
}
if (true == empty($network) || $network == 'live') {
$network = 'https://bitpay.com/api/invoice/';
} else {
$network = 'https://test.bitpay.com/api/invoice/';
if (!$btcpayUrl) {
$btcpayUrl = $bpOptions['btcpayUrl'];
}
$response = bpCurl($network . $invoiceId, $apiKey);
$btcpayUrl = getFullUri($btcpayUrl,"/invoices");
$response = bpCurl($btcpayUrl . '/' . $invoiceId, $apiKey);
if (is_string($response)) {
return $response; // error
}
$response['posData'] = json_decode($response['posData'], true);
$response['posData'] = json_decode($response['data']['posData'], true);
if($bpOptions['verifyPos']) {
$response['posData'] = $response['posData']['posData'];
if ($bpOptions['verifyPos']) {
$response['posData'] = $response['data']['posData'];
}
return $response;

View File

@ -25,24 +25,24 @@
global $bpOptions;
// Please look carefully throught these options and adjust according to your installation.
// Please look carefully through these options and adjust according to your installation.
// Alternatively, any of these options can be dynamically set upon calling the functions in bp_lib.
// REQUIRED Api key you created at bitpay.com
// REQUIRED Api key you created on your BTCPay Server store.
// example: $bpOptions['apiKey'] = 'L21K5IIUG3IN2J3';
$bpOptions['apiKey'] = '';
// Indicates whether API key is from test.bitpay.com or bitpay.com
$bpOptions['network'] = 'live';
// URI to your BTCPay server instance.
$bpOptions['btcpayUrl'] = '';
// whether to verify POS data by hashing above api key. If set to false, you should
// have some way of verifying that callback data comes from bitpay.com
// have some way of verifying that callback data comes from BTCPay Server.
$bpOptions['verifyPos'] = true;
// email where invoice update notifications should be sent
$bpOptions['notificationEmail'] = '';
// url where bitpay server should send update notifications. See API doc for more details.
// url where BTCPay Server should send update notifications. See API doc for more details.
# example: $bpNotificationUrl = 'http://www.example.com/callback.php';
$bpOptions['notificationURL'] = '';
@ -50,8 +50,7 @@ $bpOptions['notificationURL'] = '';
# example: $bpNotificationUrl = 'http://www.example.com/confirmation.php';
$bpOptions['redirectURL'] = '';
// This is the currency used for the price setting. A list of other pricing
// currencies supported is found at bitpay.com
// This is the currency used for the price setting.
$bpOptions['currency'] = 'BTC';
// Indicates whether anything is to be shipped with
@ -66,4 +65,4 @@ $bpOptions['physical'] = 'true';
$bpOptions['fullNotifications'] = 'true';
// transaction speed: low/medium/high. See API docs for more details.
$bpOptions['transactionSpeed'] = 'low';
$bpOptions['transactionSpeed'] = 'medium';

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -2,7 +2,7 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2011-2018 BitPay
* Copyright (c) 2011-2018 BitPay, BTCPay server (c) 2019-2022
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -36,11 +36,11 @@ if (file_exists('../../../dbconnect.php')) {
} else if (file_exists('../../../init.php')) {
include '../../../init.php';
} else {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
die('[ERROR] In modules/gateways/btcpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
}
$gatewaymodule = 'bitpay';
$gatewaymodule = 'btcpay';
$GATEWAY = getGatewayVariables($gatewaymodule);
@ -51,8 +51,8 @@ $result = Capsule::connection()->select("SELECT tblinvoices.total, tblinvoice
$data = (array)$result[0];
if (!$data) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: No invoice found for invoice id #' . $invoiceId);
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice id #' . $invoiceId);
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: No invoice found for invoice id #' . $invoiceId);
die('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invalid invoice id #' . $invoiceId);
}
$price = $data['total'];
@ -60,8 +60,8 @@ $currency = $data['code'];
$status = $data['status'];
if ($status != 'Unpaid') {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invoice status must be Unpaid. Status: ' . $status);
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Bad invoice status of ' . $status);
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invoice status must be Unpaid. Status: ' . $status);
die('[ERROR] In modules/gateways/btcpay/createinvoice.php: Bad invoice status of ' . $status);
}
// if convert-to option is set (gateway setting), then convert to requested currency
@ -81,16 +81,16 @@ if ($convertTo) {
$currentCurrency = (array)$result[0];
if (!$currentCurrency) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice currency of ' . $currency);
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice currency of ' . $currency);
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invalid invoice currency of ' . $currency);
die('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invalid invoice currency of ' . $currency);
}
$result = Capsule::connection()->select("SELECT code, rate FROM tblcurrencies where `id` = $convertTo");
$convertToCurrency = (array)$result[0];
if (!$convertToCurrency) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo);
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo);
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo);
die('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo);
}
$currency = $convertToCurrency['code'];
@ -105,18 +105,28 @@ unset($options['systemURL']);
unset($options['redirectURL']);
$options['notificationURL'] = $_POST['systemURL'].'/modules/gateways/callback/bitpay.php';
$options['redirectURL'] = !empty($GATEWAY['redirectURL']) ? $GATEWAY['redirectURL'] : $_POST['systemURL'];
$options['apiKey'] = $GATEWAY['apiKey'];
$options['notificationURL'] = $_POST['ipnURL'];
$options['redirectURL'] = $options['redirectURL'] = !empty($GATEWAY['redirectURL']) ? $GATEWAY['redirectURL'] : $_POST['systemURL'].'viewinvoice.php?id='.$_POST['invoiceId'].'&paymentsuccess=true';
$options['apiKey'] = $GATEWAY['apiKey'];
$options['transactionSpeed'] = $GATEWAY['transactionSpeed'];
$options['currency'] = $currency;
$options['network'] = $GATEWAY['network'];
$options['currency'] = $currency;
$options['btcpayUrl'] = rtrim($GATEWAY['btcpayUrl'], "/") . "/";
$options['btcpayUrlTor'] = rtrim($GATEWAY['btcpayUrlTor'], "/") . "/";
$invoice = bpCreateInvoice($invoiceId, $price, $invoiceId, $options);
$invoice = bpCreateInvoice($invoiceId, $price, $invoiceId, $options);
if (isset($invoice['error'])) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invoice error: ' . var_export($invoice['error'], true));
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invoice error: ' . var_export($invoice['error'], true));
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invoice error: ' . var_export($invoice['error'], true));
die('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invoice error: ' . var_export($invoice['error'], true));
} else {
header('Location: ' . $invoice['url']);
if (!empty($invoice['data']['url'])) {
$is_tor_enabled = preg_match("/\.onion$/", $_SERVER['HTTP_HOST']) && $options['btcpayUrlTor'] != '';
if ($is_tor_enabled) {
$invoice['data']['url'] = str_replace($options['btcpayUrl'], $options['btcpayUrlTor'], $invoice['data']['url']);
}
header('Location: ' . $invoice['data']['url']);
} else {
$invError = "Something went wrong when creating the invoice and redirecting to BTCPay Server.";
bpLog('[ERROR] In modules/gateways/btcpay/createinvoice.php: Invoice error: ' . $invError);
}
}

View File

@ -1,4 +1,4 @@
<?php
global $version;
$version = "1.1.2";
$version = "3.2.2";

View File

@ -0,0 +1,26 @@
{
"schema": "1.0",
"type": "whmcs-gateways",
"name": "btcpay",
"license": "mit",
"category": "payments",
"description": {
"name": "BTCPay Server (Legacy API)",
"tagline": "Accept non-custodial Bitcoin and Altcoin payments.",
"long": "With BTCPay Server you can become your own payment processor with no 3rd party taking a cut or censoring transactions."
},
"logo": {
"filename": "btcpay.png"
},
"support": {
"homepage": "https:\/\/btcpayserver.org\/",
"support_url": "https://github.com/btcpayserver/whmcs-plugin\/issues",
"docs_url": "https:\/\/github.com\/btcpayserver\/whmcs-plugin\/blob\/master\/GUIDE.md"
},
"authors": [
{
"name": "BTCPay Server Integrations Team",
"homepage": "https:\/\/btcpayserver.org\/"
}
]
}

View File

@ -35,37 +35,37 @@ if (file_exists('../../../dbconnect.php')) {
} else if (file_exists('../../../init.php')) {
include '../../../init.php';
} else {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
bpLog('[ERROR] In modules/gateways/callback/btcpay.php: include error: Cannot find dbconnect.php or init.php');
die('[ERROR] In modules/gateways/callback/btcpay.php: include error: Cannot find dbconnect.php or init.php');
}
require_once '../bit-pay/bp_lib.php';
require_once '../btcpay/bp_lib.php';
$gatewaymodule = 'bitpay';
$gatewaymodule = 'btcpay';
$GATEWAY = getGatewayVariables($gatewaymodule);
if (!$GATEWAY['type']) {
logTransaction($GATEWAY['name'], $_POST, 'Not activated');
bpLog('[ERROR] In modules/gateways/callback/bitpay.php: bitpay module not activated');
die('[ERROR] In modules/gateways/callback/bitpay.php: Bitpay module not activated.');
bpLog('[ERROR] In modules/gateways/callback/btcpay.php: btcpay module not activated');
die('[ERROR] In modules/gateways/callback/btcpay.php: BTCPay module not activated.');
}
$response = bpVerifyNotification($GATEWAY['apiKey'], $GATEWAY['network']);
$response = bpVerifyNotification($GATEWAY['apiKey'], $GATEWAY['btcpayUrl']);
if (true === is_string($response) || true === empty($response)) {
logTransaction($GATEWAY['name'], $_POST, $response);
die('[ERROR] In modules/gateways/callback/bitpay.php: Invalid response received: ' . $response);
bpLog('[ERROR] In modules/gateways/callback/btcpay.php: Invalid response received: ' . $response);
die('[ERROR] In modules/gateways/callback/btcpay.php: Invalid response received: ' . $response);
} else {
$invoiceid = $response['posData'];
$whmcsid = $response['data']['orderId'];
// Checks invoice ID is a valid invoice number or ends processing
$invoiceid = checkCbInvoiceID($invoiceid, $GATEWAY['name']);
$whmcsid = checkCbInvoiceID($whmcsid, $GATEWAY['name']);
$transid = $response['id'];
$transid = $response['data']['id'];
$invoice = Capsule::table('tblinvoices')->where('id', $invoiceid)->first();
$invoice = Capsule::table('tblinvoices')->where('id', $whmcsid)->first();
$userid = $invoice->userid;
// Checks transaction number isn't already in the database and ends processing if it does
@ -77,7 +77,7 @@ if (true === is_string($response) || true === empty($response)) {
// left blank, this will auto-fill as the full balance
$amount = '';
switch ($response['status']) {
switch ($response['data']['status']) {
case 'paid':
// New payment, not confirmed
logTransaction($GATEWAY['name'], $response, 'The payment has been received, but the transaction has not been confirmed on the bitcoin network. This will be updated when the transaction has been confirmed.');
@ -85,13 +85,13 @@ if (true === is_string($response) || true === empty($response)) {
case 'confirmed':
// Apply Payment to Invoice
Capsule::table('tblclients')->where('id', $userid)->update(array('defaultgateway' => $gatewaymodule));
addInvoicePayment($invoiceid, $transid, $amount, $fee, $gatewaymodule);
addInvoicePayment($whmcsid, $transid, $amount, $fee, $gatewaymodule);
logTransaction($GATEWAY['name'], $response, 'The payment has been received, and the transaction has been confirmed on the bitcoin network. This will be updated when the transaction has been completed.');
break;
case 'complete':
// Apply Payment to Invoice
Capsule::table('tblclients')->where('id', $userid)->update(array('defaultgateway' => $gatewaymodule));
addInvoicePayment($invoiceid, $transid, $amount, $fee, $gatewaymodule);
addInvoicePayment($whmcsid, $transid, $amount, $fee, $gatewaymodule);
logTransaction($GATEWAY['name'], $response, 'The transaction is now complete.');
break;
case 'expired':