2017 © Pedro Peláez
 

library brainblocks

An integration helper for taking Nano payments via BrainBlocks

image

binarycabin/brainblocks

An integration helper for taking Nano payments via BrainBlocks

  • Wednesday, June 27, 2018
  • by binarycabin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 27 Installations
  • HTML
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 440 % Grown

The README.md

BrainBlocks for Laravel

An integration helper for taking Nano payments via BrainBlocks.io, (*1)

This package adds a few helpers when adding a BrainBlocks button with Laravel, (*2)

Installation

composer require binarycabin/brainblocks

In .env, add your Nano wallet address the button will send to:, (*3)

BRAINBLOCKS_RECEIVE_ADDRESS=nano_1999...

Adding Buttons

Simply include the button view where you would like the button to appear. Be sure to include the amount (in rai) that the button will take as well as the url the button will POST to with a valid brainblocks token:, (*4)

@include('brainblocks::button',['amount'=>1000,'action'=>url('/pay')])

You can add multiple buttons on this page using this include. Then at the bottom of the page, be sure to add your javascript, (*5)

@include('brainblocks::scripts')

Validating BrainBlocks Responses

In your POST route, call the, (*6)

Route::post('/pay', function(Request $request){
    $brainBlocksResponse = \BrainBlocks::getTokenResponse($request->brainblocks_token);
    $responseIsValid = \BrainBlocks::validateResponse($brainBlocksResponse,[
        'amount_rai' => 200,
    ]);
    dump($brainBlocksResponse);
    if($responseIsValid){
        //.. do successful stuff
    }
});

BrainBlocks::getTokenResponse will return the full response from the BrainBlocks, this can be validated manually or you can use the validateResponse helper., (*7)

By default, the validateResponse helper will make sure: - the fulfilled property is true - the "destination" address matches the address your config The second property takes an array of additional validations you would like to check, for example checking the amount., (*8)

Custom Currencies

In addition to the default "rai", you can change the currency used to any of the supported currencies listed on brainblocks.io, (*9)

@include('brainblocks::button',['amount'=>5,'currency'=>'usd','action'=>url('/pay')])

Be sure to update your validator to look for the correct currency and amount, (*10)

$responseIsValid = \BrainBlocks::validateResponse($brainBlocksResponse,[
    'amount' => 5,
    'currency' => 'usd',
]);

Custom Destination

If you need a specific button to go to a destination address other than the one set in your configuration, you can add it as an option as well, (*11)

@include('brainblocks::button',['amount'=>1000,'destination'=>'nano_11223344...','action'=>url('/pay')])

Be sure to update your validator to look for the changed destination instead of the default, (*12)

$responseIsValid = \BrainBlocks::validateResponse($brainBlocksResponse,[
    'amount_rai' => 1000,
    'destination' => 'xrb_1kojnrrw8rtybqsqk5uh7bcioo8thkiqjkibmn43togd416gzfye6j44b9sc',
]);

Donate with NaNote, (*13)

The Versions

27/06 2018

dev-master

9999999-dev

An integration helper for taking Nano payments via BrainBlocks

  Sources   Download

MIT

The Requires

 

27/06 2018

1.2

1.2.0.0

An integration helper for taking Nano payments via BrainBlocks

  Sources   Download

MIT

The Requires

 

29/05 2018

1.1

1.1.0.0

An integration helper for taking Nano payments via BrainBlocks

  Sources   Download

MIT

The Requires

 

26/05 2018

1.0

1.0.0.0

An integration helper for taking Nano payments via BrainBlocks

  Sources   Download

MIT

The Requires