PHP code example of oseintow / baremetrics-api

1. Go to this page and download the library: Download oseintow/baremetrics-api 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/ */

    

oseintow / baremetrics-api example snippets

5


'providers' => [
    ...
    Oseintow\Baremetrics\BaremetricsServiceProvider::class,
],
5


'aliases' => [
    ...
    'Baremetrics' => Oseintow\Baremetrics\Facades\Baremetrics::class,
],
5
use Oseintow\Baremetrics\Facades\Baremetrics;

Route::get("baremetric_sources",function()
{
    // If you have "BAREMETRICS_API_KEY" set in your env file then the will be no need to set `setApiKey`
    $apiKey = "xx-xx-x-xx-xx-xx"
    
    // Use isLiveMode to set your mode to production / sandbox
    // True for production and false for sandbox
    // It is false by default
    $response = Baremetrics::setApiKey($apikey)->isLiveMode(true)->get("sources");
    
    $sourceId = "";
    
    foreach($response['sources] as $sourece){
        if($source['provider'] == "baremetrics"){
            $sourceId = $source['id'];
        }
    }
});
5
Baremetrics::get("resource uri", ["query string params"]);
Baremetrics::post("resource uri", ["post body"]);
Baremetrics::put("resource uri", ["put body"]);
Baremetrics::delete("resource uri");
5
$sourceId = "1233243";
$products = Baremetrics::setApiKey("xx-xxx-xx-xx-xx")->get("{$sourceId}/plans");
5
// returns Collection
$sourceId = "1233243";
$baremetrics = Baremetrics::setApiKey("xx-xxx-xx-xx-xx");
$plans = $baremetrics->get(""{$sourceId}/plans", ["search"=> "xxx-xxxx-xxx"]);
5
use Illuminate\Http\Request;
use Oseintow\Baremetrics\Baremetrics;

class Foo
{
    protected $baremetrics;

    public function __construct(Baremetrics $baremetrics)
    {
        $this->baremetrics = $baremetrics;
    }

    /*
    * returns Collection
    */
    public function getPlans(Request $request)
    {
        $sourceId = "xxxx-xx-xx";
        
        $plans = $this->baremetrics->setApiKey("xx-xxx-xx-xx-xx")
            ->get('{$sourceId}/plans');
    }
}
5
Baremetrics::getHeaders();
5
Baremetrics::getHeader("Content-Type");
5
if(Baremetrics::hasHeader("Content-Type")){
    echo "Yes header exist";
}
5
Baremetrics::getStatusCode(); // 200
Baremetrics::getReasonPhrase(); // ok
5
use Oseintow\Baremetrics\Baremetrics;

$baremetrics = new Baremetrics();

$sources = $baremetrics->isLiveMode(true)->setApiKey("xxx-xxxx-xxxx-xxx-xx")->get("sources");

$sourceId= "123456";
$plans = $baremetrics->get("{$sourceid}/plans");