Ejemplo n.º 1
0
function shoGocoinToken()
{
    $code = isset($_REQUEST['code']) && !empty($_REQUEST['code']) ? $_REQUEST['code'] : '';
    $client_id = MODULE_PAYMENT_GOCOIN_MERCHANT_ID;
    $client_secret = MODULE_PAYMENT_GOCOIN_ACCESS_KEY;
    try {
        $token = GoCoin::requestAccessToken($client_id, $client_secret, $code, null);
        echo "<b>Copy this Access Token into your GoCoin Module: </b><br>" . $token;
    } catch (Exception $e) {
        echo "Problem in getting Token: " . $e->getMessage();
    }
    die;
}
Ejemplo n.º 2
0
 function after_process()
 {
     include_once DIR_WS_INCLUDES . 'gocoinlib/src/GoCoin.php';
     global $messageStack;
     global $insert_id, $db, $order, $sendto, $currency;
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $php_version_allowed = true;
     } else {
         $php_version_allowed = false;
     }
     $customer_id = $_SESSION['customer_id'];
     $customer = $order->billing['firstname'] . ' ' . $order->billing['lastname'];
     $callback_url = $this->baseUrl . "ext/modules/payment/gocoinpay/callback_url.php";
     $return_url = $this->baseUrl . "checkout_success.php";
     $merchant_id = MODULE_PAYMENT_GOCOIN_MERCHANT_ID;
     $access_token = MODULE_PAYMENT_GOCOIN_ACCESS_KEY;
     $stage = "GoCoin Payment In CheckOut :";
     if (empty($access_token)) {
         $msg = 'Improper Gateway set up. API Key not found.';
         $this->osLog($stage, $msg);
         $json['error'] = $msg;
     } elseif (empty($merchant_id)) {
         $msg = 'Improper Gateway set up. Merchant ID not found.';
         $json['error'] = $msg;
         $this->osLog($stage, $msg);
     } elseif ($php_version_allowed == false) {
         $msg = 'The minimum PHP version required for GoCoin plugin is 5.3.0.';
         $json['error'] = $msg;
         $this->osLog($stage, $msg);
     } else {
         $options = array("type" => 'bill', 'price_currency' => $coin_currency, 'base_price' => $order->info['total'], 'base_price_currency' => $order->info['currency'], 'callback_url' => $callback_url, 'redirect_url' => $return_url, 'order_id' => $insert_id, 'customer_name' => $customer, 'customer_address_1' => $order->billing['street_address'], 'customer_address_2' => '', 'customer_city' => $order->delivery['city'], 'customer_region' => $order->delivery['state'], 'customer_postal_code' => $order->customer['postcode'], 'customer_country' => $order->billing['country']['title'], 'customer_phone' => $order->customer['telephone'], 'customer_email' => $order->customer['email_address']);
         $signature = $this->sign($options, $access_token);
         $options['user_defined_8'] = $signature;
         try {
             $invoice = GoCoin::createInvoice($access_token, $merchant_id, $options);
             $url = $invoice->gateway_url;
             $json['success'] = $url;
         } catch (Exception $e) {
             $msg = $e->getMessage();
             $json['error'] = $msg;
             $this->osLog($stage, $msg);
         }
     }
     if (isset($json['error']) && $json['error'] != '') {
         $messageStack->add_session('checkout_payment', $json['error'] . '<!-- [' . $this->code . '] -->', 'error');
         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . base64_encode($json['error']), 'SSL'));
     } elseif (isset($json['success']) && $json['success'] != '') {
         $_SESSION['cart']->reset(true);
         tep_redirect($url);
     }
     return false;
 }
Ejemplo n.º 3
0
<?php

ini_set('display_errors', 1);
//include the config and the gocoin api
require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../../src/GoCoinAdmin.php';
//pick a token
$token = $TOKENS['full_access'];
//echo an HTML block
echo '<html><head><title>GoCoin Admin User Test</title></head><body>' . "\n";
//get the current user
$user = GoCoin::getUser($token);
//get a list of users (admin only function)
$users = GoCoinAdmin::listUsers($token);
//show the current user
echo '<hr/>' . "\n";
echo '<h3 style="color:blue">Current User</h3>';
showObject($user);
//show the application users
echo '<hr/>' . "\n";
echo '<h3 style="color:blue">Application Users</h3>';
if (!empty($users)) {
    foreach ($users as $u) {
        showObject($u);
        echo '<hr/>' . "\n";
        break;
    }
    echo '<div style="color:#aa0000">NOTE: There are ' . (sizeof($users) - 1) . ' other users not shown</div>';
}
//create user tests
Ejemplo n.º 4
0
//pick a token
$token = $TOKENS['full_access'];
//echo an HTML block
echo '<html><head><title>GoCoin Account Test</title></head><body>' . "\n";
echo '<h3 style="color:blue">Merchant Accounts</h3>';
//get accounts for this merchant
$accounts = GoCoin::getAccounts($token, MERCHANT_ID);
if (!empty($accounts)) {
    foreach ($accounts as $account) {
        showObject($account);
        echo '<hr/>' . "\n";
    }
}
if (!empty(ACCOUNT_ID)) {
    //example search criteria array
    $criteria = array('per_page' => 10);
    echo '<h3 style="color:blue">Account Transactions</h3>';
    //search transactions with criteria
    $xactions = GoCoin::getAccountTransactions($token, ACCOUNT_ID, $criteria);
    //var_dump($xactions);
    if (!empty($xactions) && $xactions->paging_info->total > 0) {
        foreach ($xactions->transactions as $xaction) {
            showObject($xaction);
            echo '<hr/>' . "\n";
        }
    } else {
        echo '<div style="color:#aa0000">There are no transactions for this account</div>' . "\n";
    }
}
//close our HTML block
echo '</body></html>' . "\n";
 /**
  * @return the transactions that match the given criteria
  */
 public static function getAccountTransactions($token, $account_id, $criteria = NULL)
 {
     $client = GoCoin::getClient($token);
     $xactions = $client->api->accounts->getAccountTransactions($account_id, $criteria);
     if ($xactions === FALSE) {
         throw new Exception($client->getError());
     } else {
         return $xactions;
     }
 }
Ejemplo n.º 6
0
<?php

ini_set('display_errors', 1);
//include the config and the gocoin api
require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../../src/GoCoinAdmin.php';
//pick a token
$token = $TOKENS['full_access'];
//echo an HTML block
echo '<html><head><title>GoCoin Admin Merchant User Test</title></head><body>' . "\n";
echo '<h3 style="color:blue">Merchant Users</h3>';
//get a list of all merchant users
$users = GoCoin::getMerchantUsers($token, MERCHANT_ID);
if (!empty($users)) {
    foreach ($users as $key => $user) {
        showObject($user);
        echo '<hr/>' . "\n";
        //break;
    }
    //echo '<div style="color:#aa0000">NOTE: There are ' . (sizeof($users) - 1) . ' other merchant users not shown</div>';
}
//add a merchant user
echo '<h3 style="color:blue">Add Merchant User</h3>';
$add = GoCoinAdmin::addMerchantUser($token, MERCHANT_ID, MERCHANT_USER_ID);
var_dump($add);
//remove a merchant user
echo '<h3 style="color:blue">Delete Merchant User</h3>';
$del = GoCoinAdmin::deleteMerchantUser($token, MERCHANT_ID, MERCHANT_USER_ID);
var_dump($del);
//close our HTML block
Ejemplo n.º 7
0
    }
    echo '</ul>' . "\n";
}
//example search criteria array
$criteria = array('merchant_id' => MERCHANT_ID, 'start_time' => '2014-03-14T00:00:00.000Z', 'per_page' => 10);
echo '<hr/>' . "\n";
echo '<h3 style="color:blue">Recent Invoices</h3>';
//search invoices with criteria
$invoices = GoCoin::searchInvoices($token, $criteria);
if (!empty($invoices) && property_exists($invoices, 'invoices')) {
    foreach ($invoices->invoices as $invoice) {
        showObject($invoice);
        echo '<hr/>' . "\n";
    }
}
echo '<h3 style="color:blue">Specific Invoices</h3>';
//get a specific invoice
$specific = GoCoin::getInvoice($token, INVOICE_ID);
showObject($invoice);
$NEW_INVOICE = FALSE;
if ($NEW_INVOICE) {
    echo '<hr/>' . "\n";
    echo '<h3 style="color:blue">New Invoice</h3>';
    //create a new invoice
    $new_invoice = array('price_currency' => 'BTC', 'base_price' => '456.00', 'base_price_currency' => 'USD', 'notification_level' => 'all', 'confirmations_required' => 5);
    $new_invoice = GoCoin::createInvoice($token, MERCHANT_ID, $new_invoice);
    //var_dump($new_invoice);
    showObject($new_invoice);
}
//close our HTML block
echo '</body></html>' . "\n";
Ejemplo n.º 8
0
}
//get all conversions
echo '<hr/>' . "\n";
echo '<h3 style="color:blue">All Conversions</h3>';
$conversions = GoCoin::getCurrencyConversions($token, MERCHANT_ID);
var_dump($conversions);
if (!empty($conversions)) {
    foreach ($conversions as $conversion) {
        showObject($conversion);
    }
}
//request a conversion
$DO_CONVERSION = TRUE;
if ($DO_CONVERSION) {
    echo '<h3 style="color:blue">Requested Conversion</h3>';
    try {
        $conversion = GoCoin::requestCurrencyConversion($token, MERCHANT_ID, 1);
        showObject($conversion);
    } catch (Exception $e) {
        //var_dump($e);
        echo '<div style="color:#aa0000">' . $e->getMessage() . '</div>' . "\n";
    }
}
//show a specific conversion id
if (!empty(CONVERSION_ID)) {
    echo '<h3 style="color:blue">Specific Conversion</h3>';
    $specific = GoCoin::requestCurrencyConversion($token, MERCHANT_ID, 1);
    showObject($specific);
}
//close our HTML block
echo '</body></html>' . "\n";
Ejemplo n.º 9
0
 public function testGetMerchantUsers()
 {
     if (!$this->doTest(__FUNCTION__)) {
         return;
     }
     //perform assertion
     $this->assertEquals(GoCoin::getApiMode(), 'test');
     $this->assertNotEmpty(TOKEN);
     //get a list of all merchant users
     $users = GoCoin::getMerchantUsers(TOKEN, MERCHANT_ID);
     $this->assertGreaterThanOrEqual(1, sizeof($users));
     $this->assertEquals($users[0]->id, USER_ID);
     echo '[DEBUG]: SUCCESS: ' . sizeof($users) . ' - ' . $users[0]->id . "\n";
 }
 /**
  * Process payment for woocommerce checkout
  * 
  * @param mixed $order_id
  */
 function process_payment($order_id)
 {
     global $woocommerce, $wpdb;
     $access_token = $this->settings['accessToken'];
     $merchant_id = $this->settings['merchantId'];
     $logger = new WC_Logger();
     // Check to make sure we have an access token (API Key)
     if (empty($access_token)) {
         $msg = 'Improper Gateway set up. Access token not found.';
         $logger->add('gocoin', $msg);
         $woocommerce->add_error(__($msg));
     } elseif (empty($merchant_id)) {
         $msg = 'Improper Gateway set up. Merchant ID not found.';
         $logger->add('gocoin', $msg);
         $woocommerce->add_error(__($msg));
     } else {
         // Build the WooCommerce order, is has status "Pending"
         $order = new WC_Order($order_id);
         // Handle breaking route changes for after-purchase pages
         if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) {
             $redirect_url = $this->get_return_url($this->order);
         } else {
             $redirect_url = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id'))));
         }
         $callback_url = plugin_dir_url(__FILE__) . 'gocoin-callback.php';
         $currency = get_woocommerce_currency();
         $options = array("type" => 'bill', "base_price" => $order->order_total, "base_price_currency" => $currency, "callback_url" => $callback_url, "redirect_url" => $redirect_url, "order_id" => $order_id, "customer_name" => $order->shipping_first_name . ' ' . $order->shipping_last_name, "customer_address_1" => $order->shipping_address_1, "customer_address_2" => $order->shipping_address_2, "customer_city" => $order->shipping_city, "customer_region" => $order->shipping_state, "customer_postal_code" => $order->shipping_postcode, "customer_country" => $order->shipping_country, "customer_phone" => $order->shipping_phone, "customer_email" => $order->shipping_email);
         // Sign invoice with access token, if this fails we should still allow user to check out.
         if ($signature = Util::sign($options, $access_token)) {
             $options['user_defined_8'] = $signature;
         }
         try {
             $invoice = GoCoin::createInvoice($access_token, $merchant_id, $options);
             $url = $invoice->gateway_url;
             $woocommerce->cart->empty_cart();
             return array('result' => 'success', 'redirect' => $url);
         } catch (Exception $e) {
             $msg = $e->getMessage();
             $order->add_order_note(var_export($msg));
             $logger->add('gocoin', $msg);
             $woocommerce->add_error(__($msg));
         }
     }
 }
Ejemplo n.º 11
0
<?php

require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/../src/GoCoin.php';
//request a token if we're been redirected back to here with a code
if (array_key_exists('code', $_REQUEST)) {
    try {
        $token = GoCoin::requestAccessToken(CLIENT_ID, CLIENT_SECRET, $_REQUEST['code'], REDIRECT_URL);
        echo '<div><b>Token: </b>' . $token . '</div>' . "\n";
        echo '<div><b>Scope: </b>' . SCOPE . '</div>' . "\n";
    } catch (Exception $e) {
        echo '<div style="color:#aa0000">Error: ' . $e->getMessage() . '</div>' . "\n";
    }
} else {
    $auth_url = GoCoin::requestAuthorizationCode(CLIENT_ID, CLIENT_SECRET, SCOPE, REDIRECT_URL);
    header("Location: {$auth_url}");
    return;
}
Ejemplo n.º 12
0
//confirmation tests
$CONFIRM = FALSE;
if ($CONFIRM) {
    echo '<h3 style="color:blue">Confirmation Test</h3>';
    if (empty(CONFIRM_TOKEN)) {
        //request a confirmation email
        $confirm_email = GoCoin::requestConfirmationEmail($token, USER_EMAIL);
        if ($confirm_email->code == '204') {
            echo '<div style="color:#008800">Confirmation email requested!</div>';
        } else {
            echo '<div style="color:#aa0000">Confirmation email failure:</div>';
            var_dump($confirm_email);
        }
    } else {
        //confirm a user account
        $confirm_account = GoCoin::confirmUser($token, USER_ID, CONFIRM_TOKEN);
        if ($confirm_account->code == '301') {
            echo '<div style="color:#008800">Confirm account success!</div>';
        } else {
            echo '<div style="color:#aa0000">Confirm account failure:</div>';
            var_dump($confirm_account);
        }
        //the following code is an example of actually following
        //the redirect if one has been given in the method call
        $REDIRECT = FALSE;
        if ($REDIRECT) {
            if (property_exists($confirm_account, 'location')) {
                header("Location: " . $confirm_account->location);
                return;
            }
        }