PHP code example of barzahlen / barzahlen-php

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

    

barzahlen / barzahlen-php example snippets


use Barzahlen\Client;
use Barzahlen\Exception\ApiException;

$client = new Client('12345', 'f2a173a210c7c8e7e439da7dc2b8330b6c06fc04', true);
$client->setUserAgent('Awesome Project v1.0.1');

try {
    $response = $client->handle($request);
    $stdClass = json_decode($response);
    $array = json_decode($response, true);
} catch (ApiException $e) {
    // @TODO: handle exception
}

use Barzahlen\Request\CreateRequest;

$request = new CreateRequest();
$request->setSlipType('payment');
$request->setCustomerKey('LDFKHSLFDHFL');
$request->setTransaction('14.95', 'EUR');

use Barzahlen\Request\CreateRequest;

$parameters = array(
    'slip_type' => 'payment',
    'customer' => array(
        'key' => 'LDFKHSLFDHFL'
    ),
    'transactions' => array(
        array(
            'amount' => '14.95',
            'currency' => 'EUR'
        )
    )
);

$request = new CreateRequest();
$request->setBody($parameters);

use Barzahlen\Request\CreateRequest;

$json = '{
  "slip_type": "payment",
  "customer": {
    "key": "LDFKHSLFDHFL"
  },
  "transactions": [
    { "currency": "EUR", "amount": "123.34" }
  ]
}';

$request = new CreateRequest();
$request->setBody($json);

use Barzahlen\Request\CreateRequest;

$request = new CreateRequest();
$request->setSlipType('refund');
$request->setForSlipId('slp-1b41145c-2dd3-4e3f-bbe1-72c09fbf3f94');
$request->setTransaction('-14.95', 'EUR');

use Barzahlen\Request\CreateRequest;

$request = new CreateRequest();
$request->setSlipType('payout');
$request->setCustomerKey('LDFKHSLFDHFL');
$request->setTransaction('-14.95', 'EUR');

$request->setReferenceKey('REFKEY123');
$request->setHookUrl('https://www.example.tld/barzahlen/callback');
$request->setExpiresAt('2016-04-01T12:34:56Z');
$request->setCustomerKey('[email protected]');
$request->setCustomerCellPhone('01234567910');
$request->setCustomerEmail('[email protected]');
$request->setCustomerLanguage('de-DE');
$request->setAddress(array(
            'street_and_no' => 'Wallstr. 14a',
            'zipcode' => '10179',
            'city' => 'Berlin',
            'country' => 'DE'
        ));
$request->addMetadata('promo', 'summer2016');

$expire = new \DateTime();
$expire->modify('+1 week');

$request->setExpiresAt($expire)
        ->setCustomer(array(
            'cell_phone' => '01234567910'
            'key' => '[email protected]'
            'email' => '[email protected]'
            'language' => 'de-DE'
        ));

use Barzahlen\Request\UpdateRequest;

$request = new UpdateRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f');
$request->setCustomer(array(
    'email' => '[email protected]',
    'cell_phone' => '012345678910'
));
$request->setExpiresAt('2016-01-10T12:34:56Z');
$request->setTransaction('4729294329', '150.00');
$request->setReferenceKey('NEWKEY');

use Barzahlen\Request\RetrieveRequest;
use Barzahlen\Request\ResendRequest;
use Barzahlen\Request\InvalidateRequest;

// get current information on the slip
$request = new RetrieveRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f');

// resend email / text message to customer
$request = new ResendRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f', 'email');
$request = new ResendRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f', 'text_message');

// invalidate slip immediately
$request = new InvalidateRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f');

use Barzahlen\Request\RetrievePdfRequest;

$request = new RetrievePdfRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f');

// contains pdf data
$response = $client->handle($request);


use Barzahlen\Webhook;

$header = $_SERVER;
$body = file_get_contents('php://input');
$webhook = new Webhook('f2a173a210c7c8e7e439da7dc2b8330b6c06fc04');

if ($webhook->verify($header, $body)) {
    $stdClass = json_decode($body);
    $array = json_decode($body, true);
    // @TODO: send 200 status code, update order
} else {
    // @TODO: send 400 status code, log error
}
bash
composer