Merge pull request #14 from ryanxcharles/feature/add-config-port-to-curl

add config options for curl
This commit is contained in:
Ryan X. Charles 2013-12-12 11:09:46 -08:00
commit 4a9662d4f6
3 changed files with 15 additions and 4 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.swp *.swp
lib/bitpay/bp_config.php

View File

@ -0,0 +1,7 @@
<?php
$bpconfig_host="bitpay.com";
$bpconfig_port=443;
$bpconfig_hostAndPort=$bpconfig_host;
if ($bpconfig_port!=443)
$bpconfig_hostAndPort.=":".$bpconfig_port;
?>

View File

@ -1,5 +1,8 @@
<?php <?php
require_once 'bp_config_default.php';
if (file_exists('bp_config.php'))
require_once 'bp_config.php';
require_once 'bp_options.php'; require_once 'bp_options.php';
function bpCurl($url, $apiKey, $post = false) { function bpCurl($url, $apiKey, $post = false) {
@ -21,7 +24,7 @@ function bpCurl($url, $apiKey, $post = false) {
"Authorization: Basic $uname", "Authorization: Basic $uname",
); );
curl_setopt($curl, CURLOPT_PORT, 443); curl_setopt($curl, CURLOPT_PORT, $bpconfig_port);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ; curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
@ -80,7 +83,7 @@ function bpCreateInvoice($orderId, $price, $posData, $options = array()) {
$post[$o] = $options[$o]; $post[$o] = $options[$o];
$post = json_encode($post); $post = json_encode($post);
$response = bpCurl('https://bitpay.com/api/invoice/', $options['apiKey'], $post); $response = bpCurl('https://'.$bpconfig_hostAndPort.'/api/invoice/', $options['apiKey'], $post);
return $response; return $response;
} }
@ -117,7 +120,7 @@ function bpGetInvoice($invoiceId, $apiKey=false) {
if (!$apiKey) if (!$apiKey)
$apiKey = $bpOptions['apiKey']; $apiKey = $bpOptions['apiKey'];
$response = bpCurl('https://bitpay.com/api/invoice/'.$invoiceId, $apiKey); $response = bpCurl('https://'.$bpconfig_hostAndPort.'/api/invoice/'.$invoiceId, $apiKey);
if (is_string($response)) if (is_string($response))
return $response; // error return $response; // error
$response['posData'] = json_decode($response['posData'], true); $response['posData'] = json_decode($response['posData'], true);