diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/BitPayLib/BPC_Buttons.php b/BitPayLib/BPC_Buttons.php new file mode 100644 index 0000000..359acc3 --- /dev/null +++ b/BitPayLib/BPC_Buttons.php @@ -0,0 +1,24 @@ + diff --git a/BitPayLib/BPC_Client.php b/BitPayLib/BPC_Client.php new file mode 100644 index 0000000..4e5325f --- /dev/null +++ b/BitPayLib/BPC_Client.php @@ -0,0 +1,11 @@ + diff --git a/BitPayLib/BPC_Configuration.php b/BitPayLib/BPC_Configuration.php new file mode 100644 index 0000000..6ea3a0f --- /dev/null +++ b/BitPayLib/BPC_Configuration.php @@ -0,0 +1,56 @@ +apiToken = $apiToken; + if($network == 'test' || $network == null): + $this->network = $this->BPC_getApiHostDev(); + else: + $this->network = $this->BPC_getApiHostProd(); + endif; +} + +function BPC_generateHash($data) { + return hash_hmac('sha256', $data, sha1($this->BPC_getAPIToken())); +} + +function BPC_checkHash($data,$hash_key) { + if(hash_equals($hash_key,hash_hmac('sha256', $data, sha1($this->BPC_getAPIToken())))){ + return true; + }; + return false; +} + +function BPC_getAPIToken() { + return $this->apiToken; +} + +function BPC_getNetwork() { + return $this->network; +} + +public function BPC_getApiHostDev() +{ + return 'test.bitpay.com'; +} + +public function BPC_getApiHostProd() +{ + return 'bitpay.com'; +} + +public function BPC_getApiPort() +{ + return 443; +} + +public function BPC_getInvoiceURL(){ + return $this->network.'/invoices'; +} + + +} +?> diff --git a/BitPayLib/BPC_Invoice.php b/BitPayLib/BPC_Invoice.php new file mode 100644 index 0000000..b07231f --- /dev/null +++ b/BitPayLib/BPC_Invoice.php @@ -0,0 +1,106 @@ +item = $item; + + } + + public function BPC_checkInvoiceStatus($orderID) + { + + $post_fields = ($this->item->item_params); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://' . $this->item->invoice_endpoint . '/' . $post_fields->invoiceID); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + curl_close($ch); + return $result; + } + + public function BPC_createInvoice() + { + + + $post_fields = json_encode($this->item->item_params); + + $pluginInfo = $this->item->item_params->extension_version; + $request_headers = array(); + $request_headers[] = 'X-BitPay-Plugin-Info: ' . $pluginInfo; + $request_headers[] = 'Content-Type: application/json'; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://' . $this->item->invoice_endpoint); + curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + + $this->invoiceData = $result; + + curl_close($ch); + + } + + public function BPC_getInvoiceData() + { + return $this->invoiceData; + } + + public function BPC_getInvoiceURL() + { + $data = json_decode($this->invoiceData); + return $data->data->url; + } + + public function BPC_updateBuyersEmail($invoice_result, $buyers_email) + { + $invoice_result = json_decode($invoice_result); + + $update_fields = new stdClass(); + $update_fields->token = $this->item->item_params->token; + $update_fields->buyerProvidedEmail = $buyers_email; + $update_fields->invoiceId = $invoice_result->data->id; + $update_fields = json_encode($update_fields); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://' . $this->item->buyers_email_endpoint); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $update_fields); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + curl_close($ch); + return $result; + + } + + public function BPC_updateBuyerCurrency($invoice_result, $buyer_currency) + { + $invoice_result = json_decode($invoice_result); + + $update_fields = new stdClass(); + $update_fields->token = $this->item->item_params->token; + $update_fields->buyerSelectedTransactionCurrency = $buyer_currency; + $update_fields->invoiceId = $invoice_result->data->id; + $update_fields = json_encode($update_fields); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://' . $this->item->buyer_transaction_endpoint); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $update_fields); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + curl_close($ch); + return $result; + + } + +} diff --git a/BitPayLib/BPC_Item.php b/BitPayLib/BPC_Item.php new file mode 100644 index 0000000..e2be1a2 --- /dev/null +++ b/BitPayLib/BPC_Item.php @@ -0,0 +1,21 @@ +token = $config->BPC_getAPIToken(); + $this->endpoint = $config->BPC_getNetwork(); + $this->item_params = $item_params; + return $this->BPC_getItem(); +} + + +function BPC_getItem(){ + $this->invoice_endpoint = $this->endpoint.'/invoices'; + $this->buyer_transaction_endpoint = $this->endpoint.'/invoiceData/setBuyerSelectedTransactionCurrency'; + $this->item_params->token = $this->token; + return ($this->item_params); +} + +} + +?> diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2cec3ac --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014-2019 BitPay, Inc. + +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. diff --git a/README.md b/README.md index 8b13789..550b0e6 100644 --- a/README.md +++ b/README.md @@ -1 +1,43 @@ +# Notice +This is a Community-supported project. + +If you are interested in becoming a maintainer of this project, please contact us at integrations@bitpay.com. Developers at BitPay will attempt to work along the new maintainers to ensure the project remains viable for the foreseeable future. + +# Description + +Embed a shortcode on any page or post to instantly accept Bitcoin payments. + +# Quick Setup + +This version requires the following + +* A BitPay merchant account ([Test](http://test.bitpay.com) or [Production](http://www.bitpay.com)) +* An API Token ([Test](https://test.bitpay.com/dashboard/merchant/api-tokens) or [Production](https://bitpay.com/dashboard/merchant/api-tokens) + * When setting up your token, **uncheck** the *Require Authentication button* + + +# Plugin Fields + +After the plugin is activated, BitPay QuickPay will appear in the left navigation of Wordpress + + +* **Merchant Tokens** + * A ***development*** or ***production*** token will need to be set +* **Endpoint** + * Choose **Test** or **Production**, depending on your current setup. Your matching API Token must be set. + +* **Currency** + * Choose the currency to accept. If no currency is set, **USD** will be the default. + +# How to use + +In the settings page, there is a list of buttons to display. Simply adjust the price for any button, and your code will automatically be generated. + +Example: `[bitpayquickpay name ="paywithbitpaysupportedcurrencies" price="1.50"]` + +Copy and paste this code into a post/page/widget to generate a button. + + + +![](https://bitpay.com/cdn/en_US/bp-btn-pay-currencies.svg) \ No newline at end of file diff --git a/assets/banner-1544x500.png b/assets/banner-1544x500.png new file mode 100644 index 0000000..972433a Binary files /dev/null and b/assets/banner-1544x500.png differ diff --git a/assets/banner-772x250.png b/assets/banner-772x250.png new file mode 100644 index 0000000..1669436 Binary files /dev/null and b/assets/banner-772x250.png differ diff --git a/assets/icon-256x256.png b/assets/icon-256x256.png new file mode 100644 index 0000000..0f78df9 Binary files /dev/null and b/assets/icon-256x256.png differ diff --git a/assets/screenshot-1.png b/assets/screenshot-1.png new file mode 100644 index 0000000..255b7e3 Binary files /dev/null and b/assets/screenshot-1.png differ diff --git a/assets/screenshot-2.png b/assets/screenshot-2.png new file mode 100644 index 0000000..777238f Binary files /dev/null and b/assets/screenshot-2.png differ diff --git a/assets/screenshot-3.png b/assets/screenshot-3.png new file mode 100644 index 0000000..e6c7c1f Binary files /dev/null and b/assets/screenshot-3.png differ diff --git a/assets/screenshot-4.png b/assets/screenshot-4.png new file mode 100644 index 0000000..c47db9f Binary files /dev/null and b/assets/screenshot-4.png differ diff --git a/assets/screenshot-5.png b/assets/screenshot-5.png new file mode 100644 index 0000000..ca36d0d Binary files /dev/null and b/assets/screenshot-5.png differ diff --git a/assets/screenshot-6.png b/assets/screenshot-6.png new file mode 100644 index 0000000..eafa7f3 Binary files /dev/null and b/assets/screenshot-6.png differ diff --git a/assets/screenshot-7.png b/assets/screenshot-7.png new file mode 100644 index 0000000..0f21817 Binary files /dev/null and b/assets/screenshot-7.png differ diff --git a/assets/screenshot-8.png b/assets/screenshot-8.png new file mode 100644 index 0000000..7dbc011 Binary files /dev/null and b/assets/screenshot-8.png differ diff --git a/css/bitpayquickpay.css b/css/bitpayquickpay.css new file mode 100644 index 0000000..9ad803b --- /dev/null +++ b/css/bitpayquickpay.css @@ -0,0 +1,15 @@ + +.bpqpButton{ + background-color: transparent; +} +.bpqpButton:hover {opacity:.5; background-color: transparent;} +.bpqpButton:active { + background-color: transparent; +} + +.bpqpMsg{ + background-color: transparent; + display:none; +} + +.bpqpButtonClicked {opacity:.5; background-color: transparent;} diff --git a/index.php b/index.php new file mode 100644 index 0000000..c030b18 --- /dev/null +++ b/index.php @@ -0,0 +1,418 @@ +Configure + * Version: 1.0.0.0 + * Author: BitPay + * Author URI: mailto:integrations@bitpay.com?subject=BitPay QuickPay + */ + +add_action('admin_menu', 'bitpayquickpay_setup_menu'); +add_action('wp_enqueue_scripts', 'enable_bitpayquickpay_js'); +add_action('admin_enqueue_scripts', 'admin_enable_bitpayquickpay_js'); + +#autoloader +function BPQP_autoloader($class) +{ + if (strpos($class, 'BPC_') !== false): + if (!class_exists('BitPayLib/' . $class, false)): + #doesnt exist so include it + include 'BitPayLib/' . $class . '.php'; + endif; + endif; +} +spl_autoload_register('BPQP_autoloader'); + +#custom css +add_action('init', 'bitpay_quickpay_css'); +function bitpay_quickpay_css() { + wp_register_style( 'bpqp', plugins_url('/css/bitpayquickpay.css', __FILE__), false, '1.0.0', 'all'); +} +add_action('wp_enqueue_scripts', 'bpqp_enqueue_style'); +function bpqp_enqueue_style(){ + wp_enqueue_style( 'bpqp' ); + } + + + + +add_action('admin_notices', 'bitpayquickpay_check_token'); +function bitpayquickpay_check_token() +{ + $bitpay_token = get_option('bitpayquickpay_option_dev_token'); + $env = 'test'; + if (get_option('bitpayquickpay_option_endpoint') == 'production'): + $env = 'production'; + $bitpay_token = get_option('bitpayquickpay_option_prod_token'); + endif; + $config = new BPC_Configuration($bitpay_token, $env); + if (empty($bitpay_token)): ?> + + +
+ ' . strtoupper($env) . ' is invalid. Please verify your settings.');?> +
++ +
+' . $b->description . '
Setup your environment, and preview the buttons that will be added with the shortcode
'; + ?> +Use the shortcode tag to embed anywhere.
'; + + echo ''; + echo '