Skip to content

About

OpenNode PHP library for API v1

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

OpenNode PHP library for API v1

Build Status

PHP library for OpenNode API.

You can sign up for a OpenNode account at https://opennode.co for production and https://dev.opennode.co for testing.

Please note, that for testing you must generate separate API credentials on https://dev.opennode.co. API credentials generated on https://opennode.co will only work in production mode.

Composer Installation

Install library via Composer. Run the following command in your terminal:

composer require opennode/opennode-php

Manual Installation

Donwload latest release and include init.php file.

require_once('/path/opennode-php/init.php');

Getting Started

OpenNode PHP library instructions.

https://opennode.co/docs

Setting up OpenNode library

Setting default authentication

use OpenNode\OpenNode;

\OpenNode\OpenNode::config(array(
    'environment'               => 'dev', // dev OR live
    'auth_token'                => 'YOUR_AUTH_TOKEN',
    'curlopt_ssl_verifypeer'    => TRUE // default is false
));

// $order = \OpenNode\Merchant\Charge::find('c1cddabe-c27b-44a6-91e8-a8f3553dc5c7');

Setting authentication individually

use OpenNode\OpenNode;

# \OpenNode\Merchant\Charge::find($orderId, $options = array(), $authentication = array())

$charge = \OpenNode\Merchant\Charge::find('c1cddabe-c27b-44a6-91e8-a8f3553dc5c7', array(), array(
    'environment' => 'dev', // dev OR live
    'auth_token' => 'YOUR_AUTH_TOKEN'));

Creating Charge

use OpenNode\OpenNode;

$charge_params = array(
                   'description'       => '1x Book', //Optional
                   'amount'            => 20.00,
                   'currency'          => 'USD', //Optional
                   'order_id'          => 'YOUR-PLATFORM-ID', //Optional
                   'email'             => '[email protected]', //Optional
                   'name'              => 'John Doe', //Optional
                   'callback_url'      => 'https://site.com/?handler=opennode', //Optional
                   'success_url'       => 'https://example.com/order/abc123', //Optional
                   'auto_settle'       => false //Optional
               );

try {
  $charge = \OpenNode\Merchant\Charge::create($charge_params);

  echo 'LN BOLT11: ' . $charge->lightning_invoice["payreq"].PHP_EOL;
  echo 'BTC address: ' . $charge->chain_invoice['address'];

  print_r($charge);
  
} catch (Exception $e) {
  echo $e->getMessage(); // InvalidRequest Error creating order
}

Getting Charge Info

use OpenNode\OpenNode;

try {
    $charge = \OpenNode\Merchant\Charge::find('c1cddabe-c27b-44a6-91e8-a8f3553dc5c7');

    if ($charge) {
      var_dump($charge);
    }
    else {
      echo 'Charge not found';
    }
} catch (Exception $e) {
  echo $e->getMessage(); // Unauthorized Not authorized: invalid api key
}

Getting Paid Charges

try {
  $charges = \OpenNode\Merchant\Charge::findAllPaid();

  foreach ($charges as $charge) {
    print_r($charge);
  }
} catch (Exception $e) {
  echo $e->getMessage(); // Unauthorized Not authorized: invalid api key
}

About

OpenNode PHP library for API v1

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages