PHP code example of opennode / opennode-php

1. Go to this page and download the library: Download opennode/opennode-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

opennode / opennode-php example snippets




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');

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'));

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
}

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
}

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
}
bash
composer