├── .github
├── ISSUE_TEMPLATE.md
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── images
├── HD-wallet.png
├── bitcoinPayManual_demo.gif
└── bitcoinPay_demo.gif
├── resources
├── StoreCallback.php
├── StoreCheckout.php
├── bitcoinPay.css
├── bitcoinPay.js
├── bitcoinPay.php
├── bitcoinPay_conf.php
└── bitcoinPay_light.css
└── utilities
└── generateKeys.php
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Background
2 |
3 | Describe your issue here.
4 |
5 | ### Your environment
6 |
7 | * which operating system?
8 | * any other relevant environment details?
9 | * are you running LightningTip behind a reverse proxy?
10 |
11 | ### Steps to reproduce
12 |
13 | Tell us how to reproduce this issue. Please provide stacktraces and links to code in question.
14 |
15 | ### Expected behaviour
16 |
17 | Tell us what should happen.
18 |
19 | ### Actual behaviour
20 |
21 | Tell us what happens instead.
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behavior:
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | **Expected behavior**
18 | A clear and concise description of what you expected to happen.
19 |
20 | **Screenshots**
21 | If applicable, add screenshots to help explain your problem.
22 |
23 | **Desktop (please complete the following information):**
24 | - OS: [e.g. iOS]
25 | - Browser [e.g. chrome, safari]
26 | - Version [e.g. 22]
27 |
28 | **Smartphone (please complete the following information):**
29 | - Device: [e.g. iPhone6]
30 | - OS: [e.g. iOS8.1]
31 | - Browser [e.g. stock browser, safari]
32 | - Version [e.g. 22]
33 |
34 | **Additional context**
35 | Add any other context about the problem here.
36 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9 |
10 | **Describe the solution you'd like**
11 | A clear and concise description of what you want to happen.
12 |
13 | **Describe alternatives you've considered**
14 | A clear and concise description of any alternative solutions or features you've considered.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | images/
2 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at rob.clark56+github@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 michael1011, 2018 robclark56
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # bitcoinPay-PHP
2 | The files in this project will allow you to safely accept Bitcoin payments on your online PHP-based store (eStore).
3 |
4 | | Checkout Mode | Manual Mode |
5 | |---|---|
6 | |||
7 |
8 | ## FEATURES ##
9 | * Support for:
10 | * Two Modes
11 | * Checkout Mode: eStore provides memo & fiat values
12 | * Manual Mode: User provides memo & fiat values
13 | * mainnet and testnet
14 | * Multiple fiat currencies
15 | * P2PKH addresses (e.g. 1xxxxxxxx).
16 | * Segwit support is not available as this is written. If/When Segwit address generation is supported at https://www.smartbit.com.au/api then this code (without change) will support Segwit.
17 | * Exchange Rate fluctuation protection. Protection in cases of late payment broadcasts and/or late transaction mining.
18 | * Each new payment to an unused bitcoin address. With support for multiple payments to same address.
19 | * QR Code Payment Request
20 | * Copy to clipboard
21 | * Error handling
22 | * Variable Confirmations. E.g. buying a low value sticker requires only 1 confirmation. Buying a car requires 6 confirmations.
23 | * Multiple wallets
24 | * Live exchange rate conversions between Fiat and BTC
25 | * Encryption protected messaging from bitcoinPay back to the eStore site.
26 | * CSS formatting
27 |
28 | ## CREDIT ##
29 | bitcoinPay-PHP is based on [LightningTip-PHP](https://github.com/robclark56/lightningtip-PHP), which in turn is based on [LightningTip](https://github.com/michael1011/lightningtip/blob/master/README.md) by [michael1011](https://github.com/michael1011/lightningtip).
30 | ## REQUIREMENTS ##
31 | A webserver that supports:
32 |
33 | * [PHP](http://www.php.net/),
34 | * [mySQL](https://www.mysql.com/), and
35 | * [cron jobs](https://en.wikipedia.org/wiki/Cron).
36 | ## SECURITY ##
37 | At no point do you enter any of your bitcoin private keys. No hacker can spend your bitcoins.
38 |
39 | You need to keep your webserver secure, as a hacker with sufficient privileges could exchange his/her xpub for yours and customers would start paying the hacker.
40 | ## ECOMMERCE EXAMPLE - CHECKOUT MODE ##
41 | The intended audience for this project is users that have an existing online eCommerce site (eStore). Typically the customer ends up at a _checkout confirmation_ webpage with some _Pay Now_ button(s).
42 |
43 | In this project we include a very simple dummy eStore checkout page that serves as an example of how to deploy _bitcoinPay_.
44 |
45 | ## DESIGN ##
46 | The basic flow is as follows:
47 |
48 | 1. Checkout Mode:
49 | 1. eStore displays a shopping cart page with a total payable (Fiat currency)
50 | 1. User clicks _Pay_ button => Redirected to PHP file which converts fiat value to BTC, and returns a confirmation page
51 | 1. Manual Mode
52 | 1. User enters Memo and fiat value. PHP/Javascript calculates BTC value.
53 | 1. User clicks _Get Payment Request_ => Javascript passes values to PHP file which responds with a Payment Request
54 | 1. The PHP file continuously monitors the blockchain for matching transactions
55 | 1. Customer makes payment with wallet
56 | 1. If/When payment has sufficient confirmations => PHP file sends a secure message back to eStore with payment status ('Paid' or 'Underpaid') and details.
57 | 1. eStore checks message validity, and then takes appropriate action for 2 possible cases: 'Paid' or 'Underpaid'
58 |
59 | ```
60 | [eStore]<----- 'Paid'/'Underpaid'------\
61 | | |
62 | | ^
63 | \/ |
64 | [Web Browser,.js,.css]<----HTTP---->[.php]--[database]
65 | | |
66 | [QR] [Blockchain Explorer]
67 | | |
68 | \/ |
69 | [Bitcoin Wallet] -----------------[Blockchain]
70 | ```
71 | ## EXTENDED PUBLIC KEYS ##
72 | This project takes advantage of the concept of _Extended Public Keys_ (xpub). For a full understanding, see [Mastering Bitcoin, Andreas M. Antonopoulos, Chapter 5](https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc).
73 |
74 | 
75 |
76 | The important things to note are:
77 | * An xpub can generate
78 | * ALL of the public keys & addresses in your wallet.
79 | * NONE of the private keys in your wallet, so can not be used to spend your bitcoins.
80 | * Each level of the tree in the above image has a different xpub.
81 | * The xpub at the master ('m') level can generate addresses for many different coins (Bitcoin, Litecoin,...). We do not want to use the xpub from this level.
82 | * The xpub from the Bitcoin (or Bitcoin-Testnet) level is what is needed for this project.
83 |
84 | ### How does bitcoinPay-PHP get the next receiving address from the xpub? ###
85 | There is an undocumented feature at the [smartbit.com.au API](https://www.smartbit.com.au/api). If you give an xpub to the _address_ API call, it returns the next un-used receiving address.
86 |
87 | [Try it!](https://api.smartbit.com.au/v1/blockchain/address/xpub6DFUsfUukGFu5E1rjZZpwGXVw8wUcrvhxzgFgCFCdyT3nxsbQoax9BLME3pY8j2j81ewhF95gbSRiBnmseGy69E2ZYKbHrmBjwtyXkGeSES)
88 |
89 | ### What the ? xpub, ypub, zpub, tpub, upub, vpub ###
90 | The 1st character of an Extended Public Key tells you what sort of wallet it comes from. As this is written, the [smartbit.com.au API](https://www.smartbit.com.au/api) supports only _xpub_ and _tpub_.
91 |
92 | | Address Type | mainnet | testnet|
93 | |----:|-------|-------|
94 | |P2PKH (eg) | xpub (1xxxxxx)| tpub (mxxxxxx)|
95 | |P2SH (eg)| ypub (3xxxxx)| upub (2xxxxx)|
96 | |Bech32 (eg)| zpub (bc1xxx)| vpub (tb1xxx)|
97 |
98 | [More info ...](https://support.samourai.io/article/49-xpub-s-ypub-s-zpub-s)
99 |
100 | ## MONITORING FOR PAYMENTS ##
101 | This is done by a [cron job](https://en.wikipedia.org/wiki/Cron). The timing logic is as below. _EXPIRY_SECONDS_ & _MINE_SECONDS_ are set in the configuration file.
102 |
103 | * __EXPIRY_SECONDS__ defines a time window that starts as soon as the Payment Pequest is generated, and ends EXPIRY_SECONDS later. For a payment to be received it must be broadcast to the blockchain within that window. It does not have to be confirmed within that window. If the payment is broadcast after EXPIRY_SECONDS, bitcoinPay will not track the payment. This window adds a degree of protection when the FIAT/BTC exchange rate is rapidly changing.
104 | * __MINE_SECONDS__ defines a time interval that starts as soon as the Payment Request is generated, and ends MINE_SECONDS later. A non-expired payment that is mined (include in a block) within this window, and has sufficient confirmations is accepted as PAID. This window protects for the case when the sender does not include sufficient miner fee and inclusion in the blockchain takes too long, again risking invoice under-payment in fiat value.
105 |
106 | The cron job runs periodically to check pending payments. `bitcoinPay.php`can be used as the file for that cron job, if:
107 |
108 | * called as a URL with one GET parameter as follows `https://my.estore.com/bitcoinPay/bitcoinPay.php?checksettled`, or
109 | * called from the command-line as follows: `$ php bitcoinPay.php checksettled`
110 |
111 | The logic used is as follows:
112 |
113 | |Transaction received within EXPIRY_SECONDS |Mined within MINE_SECONDS|Current Currency Value >= Invoice Currency Value| Result |
114 | | :---: | :---: | :---: | :---: |
115 | |Yes|Yes|True|Paid|
116 | |Yes|Yes|False|Paid|
117 | |Yes|No|True|Paid|
118 | |Yes|No|False|Underpaid|
119 | |No|N/A|N/A|Not Tracked|
120 |
121 | ## PREPARATION ##
122 | ### 1. Get your xpub & tpub ###
123 | Your wallet software will give your xpub/tpub. Examples shown below.
124 |
125 | 1. Coinomi: Select Bitcoin -> (3-dot menu) -> Account Details
126 | 1. Electrum: Open the wallet you want to receive funds into. Wallet --> Information.
127 | 1. Make your own:
128 | * Go to https://iancoleman.io/bip39/
129 | * Generate __AND SAVE__ a new 12-word seed
130 | * Select Coin: __BTC-Bitcoin__ for mainnet, or __BTC-Bitcoin Testnet__ for testnet
131 | * Copy the _Account Extended Public Key_ (not the _BIP32 Extended Public Key_)
132 | 1. Other wallets: Check your documentation.
133 |
134 | ### 2. Generate Private/Public key pair ##
135 | To generate a Private/Public key pair, use one of these options:
136 |
137 | 1. Upload [generateKeys.php](https://github.com/robclark56/bitcoinPay-PHP/blob/master/utilities/generateKeys.php) to your host computer. Then run from the command line interface: `$ php generateKeys.php`
138 | 1. [http://travistidwell.com/jsencrypt/demo/](http://travistidwell.com/jsencrypt/demo/) (save page and run offline for extra safety)
139 |
140 | Save these keys locally for now. They will look something like this:
141 | ```
142 | -----BEGIN RSA PRIVATE KEY-----
143 | MIICXQIBAAKBgQCQ6cZssvv0DNrh5qTDq3VnT8c41V34lTa5YFgE3itTEsxBFgUl
144 | [... lines deleted...]
145 | fqE1sl6cOF5yhsoYdQ2L0uJOqBS6rkqtbnN44pSzMDph
146 | -----END RSA PRIVATE KEY-----
147 |
148 | -----BEGIN PUBLIC KEY-----
149 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQ6cZssvv0DNrh5qTDq3VnT8c4
150 | [... lines deleted...]
151 | U4UZulZEer8ss8l62QIDAQAB
152 | -----END PUBLIC KEY-----
153 | ```
154 |
155 | ### 3. Create SQL Database ###
156 | You will need to create a mySQL database. Consult your host server documentation.
157 |
158 | For example, if you have access to cPanel, [these instructions](https://support.hostgator.com/articles/cpanel/how-do-i-create-a-mysql-database-a-user-and-then-delete-if-needed) can help.
159 |
160 | After you have created your database you should have this information:
161 |
162 | |-- Parameter --|------------------ Value ----------------|--- Comment ---|
163 | |---------|-----|-------|
164 | |User||Give _ALL PRIVILEGES_|
165 | |Password||||
166 | |Host||Often is _localhost_|
167 | |Database name|||
168 |
169 | ## INSTALLATION ##
170 | * Create a folder on your webserver to host the bitcoinPay files. Consult your webserver documentation for details on where html files are stored.
171 | * e.g.: `.../public_html/bitcoinPay`
172 | * e.g.: `.../var/www/html/bitcoinPay`
173 | * e.g.: `.../htdocs/bitcoinPay`
174 |
175 | * Download the [latest release](https://github.com/robclark56/bitcoinPay-PHP/releases), and unzip.
176 | * Upload all files from the unzipped _resources_ folder to your webserver folder. __Note__: Due to JavaScript security, bitcoinPay.php must be hosted at the same domain as bitcoinPay.js
177 | * Edit files.
178 | * __bitcoinPay_conf.php__: Edit values as needed. Leave _WALLET_DEFAULT_ set to _wallet_testnet_.
179 | * __StoreCheckout.php__: Edit the CHANGE_ME section.
180 | * __StoreCallback.php__: Edit the CHANGE_ME section.
181 | * See note below on [Email Special Consideration](https://github.com/robclark56/bitcoinPay-PHP/blob/master/README.md#email-special-consideration)
182 | * __bitcoinPay.js__: Edit the CHANGE_ME section.
183 | * Create cron job to periodically check pending payments. Examples on how to run the cron job every 15 minutes are:
184 | * Servers with normal crontab-style cron jobs:
185 | * `*/15 * * * * /usr/bin/php /home/user/public_html/bitcoinPay/bitcoinPay.php checksettled`
186 | * Servers only allowing URL-style cron jobs:
187 | * Every 15 mins: `https://my.estore.com/bitcoinPay/bitcoinPay.php?checksettled`
188 | * Other:
189 | * Consult your documentation
190 |
191 | ### Email Special Consideration ###
192 | Some webserver hosts do not permit use of the PHP mail() function for security reasons. If you are in this category, there is a workaround available in bitcoinPay.
193 |
194 | * You will need to edit the _bitcoinPaySendEmail()_ function in these 2 files:
195 | * StoreCallback.php
196 | * bitcoinPay.php
197 | * Read the comments in the _bitcoinPaySendEmail()_ function in either of these files
198 | * Install PHPMailer in a folder called `PHPMailer`
199 | * Edit the _bitcoinPaySendEmail()_ function in the 2 files as below
200 | * Change ` if(false){ //false = use PHPMailer`
201 | * Edit all lines with CHANGE_ME
202 |
203 | ## TESTING - CHECKOUT MODE ##
204 | Use your browser to visit your URLs like this:
205 |
206 | * `https://my.estore.com/bitcoinPay/bitcoinPay.php?checksettled`
207 | * Note: This displays nothing if there are no pending payments, so _blank screen_ is a good response. The only point in trying this is to confirm there are no PHP configuration or syntax errors.
208 | * `https://my.estore.com/bitcoinPay/StoreCallback.php`
209 | * You should receive an email with this is the body: "Hacking Attempt???". This is the expected response when this file is called with the wrong, or no, POST parameters.
210 | * `https://my.estore.com/bitcoinPay/StoreCheckout.php`
211 | * `https://my.estore.com/bitcoinPay/StoreCheckout.php?order_id=100`
212 | * `https://my.estore.com/bitcoinPay/StoreCheckout.php?wallet=wallet_testnet`
213 | * `https://my.estore.com/bitcoinPay/StoreCheckout.php?wallet=wallet_mainnet`
214 | * `https://my.estore.com/bitcoinPay/StoreCheckout.php?wallet=wallet_mainnet&order_id=100`
215 |
216 | or you can check my test site here:
217 |
218 | (_https_ not used as this is hosted on a free web server without SSL certificates. You will not be entering any sensitive data.)
219 |
220 | * [Order for USD 80.00 (mainnet)](http://raspibolt.epizy.com/bitcoinPay/StoreCheckout.php?wallet=wallet_mainnet) CAREFUL: Don't send me real BTC.
221 | * [Order for USD 5.00 (testnet)](http://raspibolt.epizy.com/bitcoinPay/StoreCheckout.php?wallet=wallet_testnet&order_id=100)
222 |
223 | ## TESTING - MANUAL MODE ##
224 | Confirm Checkout Mode (above) is working.
225 |
226 | Use your browser to visit your URL like this:
227 |
228 | * `https://my.estore.com/bitcoinPay/bitcoinPay.php`
229 |
230 | or you can check my test site here:
231 |
232 | * [mainnet](http://raspibolt.epizy.com/bitcoinPay/bitcoinPay.php?wallet=wallet_mainnet) CAREFUL: Don't send me real BTC.
233 | * [testnet](http://raspibolt.epizy.com/bitcoinPay/bitcoinPay.php?wallet=wallet_testnet)
234 |
235 | ## LIVE USAGE ##
236 |
237 | ### 1a. Checkout Mode: Create a page on your eStore with a form something like this: ###
238 | ```php
239 |
247 |
263 | ```
264 | ### 1b. Manual Mode ###
265 | Just visit your url like: `https://my.estore.com/bitcoinPay/bitcoinPay.php`
266 | ### 2. Process Payment Notifications ###
267 | Edit _StoreCallback.php_ and change these two sections as appropriate for your eStore.
268 | ```php
269 | case 'fullyPaid':
270 | //Add code here to process fully paid order
271 | break;
272 |
273 | case 'underPaid':
274 | //Add code here to process under-paid order
275 | break;
276 | ```
277 | ### 3. Edit __bitcoinPay_conf.php__ to set the default wallet to your mainnet wallet. ###
278 | ```php
279 | define('DEFAULT_WALLET' ,'wallet_mainnet');
280 | ```
281 |
282 | ### 4. There is a light theme available for bitcoinPay. ###
283 | If you want to use it, uncomment this line in your bitcoinPay.php file:
284 | ```
285 |
286 | ```
287 | ### 5. Do not use bitcoinPay on XHTML sites ###
288 | That causes some weird scaling issues.
289 |
290 | ## LOCK DOWN SECURITY ##
291 | ### 1. Set files to Read Only ###
292 | Example using the shell command line:
293 | ```
294 | $ cd
295 | $ chmod 0444 *
296 | $ cd ..
297 | $ chmod 0555
298 | ```
299 |
300 | ---
301 | If want to tip me, you can use my [LightningTip](https://github.com/robclark56/lightningtip-PHP "lightningTip-PHP") as below.
302 | (_https_ not used as these are hosted on a free web server without SSL certificates. You will not be entering any sensitive data.)
303 | * [mainnet](http://raspibolt.epizy.com/LT/lightningTip.php)
304 | * [testnet](http://raspibolt.epizy.com/LT/lightningTip.php?testnet=1)
305 |
306 |
--------------------------------------------------------------------------------
/images/HD-wallet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robclark56/bitcoinPay-PHP/36e3894fc01ccb0a1024b9dc037a12a33c1c63dc/images/HD-wallet.png
--------------------------------------------------------------------------------
/images/bitcoinPayManual_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robclark56/bitcoinPay-PHP/36e3894fc01ccb0a1024b9dc037a12a33c1c63dc/images/bitcoinPayManual_demo.gif
--------------------------------------------------------------------------------
/images/bitcoinPay_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robclark56/bitcoinPay-PHP/36e3894fc01ccb0a1024b9dc037a12a33c1c63dc/images/bitcoinPay_demo.gif
--------------------------------------------------------------------------------
/resources/StoreCallback.php:
--------------------------------------------------------------------------------
1 | fullyPaid
12 | [data] => Array(
13 | [id] => 54
14 | [address] => mgjQF......AyEASgW
15 | [BTC] => 0.01060340
16 | [memo] => Order 42
17 | [currency] => USD
18 | [amount] => 80
19 | [minConfirmations] => 5
20 | [callback] => https://my.estore.com/bitcoinPay/StoreCallback.php
21 | [btc] => 0.01060340
22 | [confirmations] => 6
23 | [txid] => 34859e48e7106.....1d36788f5708a9
24 | [first_seen_gmt] => 2018-06-01 06:43:03
25 | [settled] => 1
26 | )
27 | [hash] => 19e2d328f20701c3....2b90a8316f47b26d
28 |
29 |
30 | Security:
31 | To counter man-in-the-middle attacks, the [hash] must be verfied as ([data][address], hashed with PRIVATE KEY).
32 |
33 | */
34 |
35 | // --- START CHANGE_ME ------------------------------------------
36 |
37 | define('EMAIL_TO' ,'me@my.estore.com'); //Leave blank to disable email notification
38 | define('EMAIL_TO_NAME' ,'Manager');
39 | define('EMAIL_FROM' ,'me@my.estore.com');
40 | define('EMAIL_FROM_NAME','eStore Callback');
41 |
42 | $eStorePubKey =
43 | '-----BEGIN PUBLIC KEY-----
44 | [... lines removed ...]
45 | -----END PUBLIC KEY-----'
46 | ;
47 |
48 | // ---- END CHANGE_ME --------------------------------------------
49 |
50 |
51 | // Decrypt hash
52 | openssl_public_decrypt(hex2bin($_POST['hash']), $decrypt_hash, $eStorePubKey);
53 |
54 | // Check and process
55 | if($_POST['data']['address'] && $decrypt_hash === $_POST['data']['address']){
56 | switch($_POST['status']){
57 | case 'fullyPaid':
58 | $message = $_POST['status'];
59 | //Add code here to process fully paid order
60 | break;
61 |
62 | case 'underPaid':
63 | $message = $_POST['status'];
64 | //Add code here to process under-paid order
65 | break;
66 |
67 | default:
68 | $message = 'Unknown status:'.$_POST['status'];
69 | }
70 | } else {
71 | $message = 'Hacking Attempt???';
72 | }
73 |
74 | // Notify
75 | bitcoinPaySendEmail(EMAIL_TO,EMAIL_TO_NAME,__FILE__,"$message\n\nPOST:".print_r($_POST,1));
76 |
77 | //////////////////////////////////////////////////////////////////////////////
78 |
79 | function bitcoinPaySendEmail($to,$to_name,$subject,$body){
80 | // By default, this function uses the built in PHP mail() function.
81 | // If your hosting service does not allow PHP mail(), then PHPMailer may work for you.
82 | // See more info here: https://infinityfree.net/support/how-to-send-email-with-gmail-smtp/
83 | // Note: The PHPMailer instructions work with more than just gmail.
84 | //
85 | if(empty($to)) return;
86 |
87 | if(true){ //false = use PHPMailer
88 | mail("$to_name <$to>",$subject,$body,"From: ".EMAIL_FROM_NAME." <".EMAIL_FROM.">");
89 | } else {
90 | date_default_timezone_set('CHANGE_ME'); //eg 'Australia/Perth'
91 | require '../PHPMailer/PHPMailerAutoload.php'; //CHANGE_ME if needed
92 | $mail = new PHPMailer;
93 | $mail->isSMTP();
94 | $mail->Host = 'CHANGE_ME'; // Which SMTP server to use.
95 | $mail->Port = CHANGE_ME; // Which port to use, 587 is the default port for TLS security.
96 | $mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
97 | $mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
98 | $mail->Username = 'CHANGE_ME';
99 | $mail->Password = 'CHANGE_ME';
100 | $mail->setFrom(EMAIL_FROM, EMAIL_FROM_NAME);
101 | $mail->addAddress($to, $name);
102 | $mail->Subject = $subject;
103 | $mail->Body = $body;
104 | $mail->send();
105 | }
106 | }
107 |
108 | ?>
109 |
--------------------------------------------------------------------------------
/resources/StoreCheckout.php:
--------------------------------------------------------------------------------
1 | 50,
29 | 'price_ea' => 0.10,
30 | 'desc' =>'HODL Sticker'
31 | );
32 |
33 | $orders[42]['products'][] =
34 | array(
35 | 'qty' => 1,
36 | 'price_ea' => 10.00,
37 | 'desc' =>'Pan Galactic Gargle Blaster'
38 | );
39 | $orders[42]['products'][] =
40 | array(
41 | 'qty' => 2,
42 | 'price_ea' => 5.00,
43 | 'desc' =>'Book of Vogon Poetry'
44 | );
45 | $orders[42]['products'][] =
46 | array(
47 | 'qty' => 3,
48 | 'price_ea' => 20.00,
49 | 'desc' =>'HODL Teeshirts'
50 | );
51 | ?>
52 |
53 |
54 |
55 |
56 | Store Checkout
57 |
61 |
62 |
63 |
64 |