|
1 | | -# BrainBlocks |
| 1 | +# BrainBlocks for Laravel |
| 2 | + |
2 | 3 | An integration helper for taking Nano payments via BrainBlocks.io |
3 | 4 |
|
4 | 5 | This package adds a few helpers when adding a BrainBlocks button with Laravel |
5 | 6 |
|
6 | | -# Installation |
| 7 | +## Installation |
7 | 8 |
|
8 | 9 | ``` |
9 | 10 | composer require binarycabin/brainblocks |
10 | 11 | ``` |
| 12 | + |
| 13 | +In .env, add your Nano wallet address the button will send to: |
| 14 | + |
| 15 | +``` |
| 16 | +BRAINBLOCKS_RECEIVE_ADDRESS=xrb_1999... |
| 17 | +``` |
| 18 | + |
| 19 | +## Adding Buttons |
| 20 | + |
| 21 | +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: |
| 22 | + |
| 23 | +``` |
| 24 | +@include('brainblocks::button',['amountRai'=>1000,'action'=>url('/pay')]) |
| 25 | +``` |
| 26 | + |
| 27 | +## Validating BrainBlocks Responses |
| 28 | + |
| 29 | +In your POST route, call the |
| 30 | + |
| 31 | +``` |
| 32 | +Route::post('/pay', function(Request $request){ |
| 33 | + $brainBlocksResponse = \BrainBlocks::getTokenResponse($request->brainblocks_token); |
| 34 | + $responseIsValid = \BrainBlocks::validateResponse($brainBlocksResponse,[ |
| 35 | + 'amount_rai' => 200, |
| 36 | + ]); |
| 37 | + dump($brainBlocksResponse); |
| 38 | + if($responseIsValid){ |
| 39 | + //.. do successful stuff |
| 40 | + } |
| 41 | +}); |
| 42 | +``` |
| 43 | + |
| 44 | +BrainBlocks::getTokenResponse will return the full response from the BrainBlocks, this can be validated manually or you can use the "validateResponse" helper. |
| 45 | + |
| 46 | +By default, the validateResponse helper will make sure: |
| 47 | +- the "fufilled" property is "true" |
| 48 | +- the "destination" address matches the address your config |
| 49 | +The second property takes an array of additional validations you would like to check, for example checking the amount. |
0 commit comments