barzahlen/barzahlen-php
Composer 安装命令:
composer require barzahlen/barzahlen-php
包简介
Barzahlen PHP Library
README 文档
README
Copyright
(c) 2016-2024, viafintech GmbH
https://www.viafintech.com
Preparation
API Credentials
The API credentials, which are necessary to use the Barzahlen API, can be received at viafintech App. After a successful registration a division ID is assigned to you as well as a payment key.
Installation
The Barzahlen PHP SDK can be installed using Composer.
composer require barzahlen/barzahlen-php
Client
The client will connect your application to the Barzahlen API v2. Initiate it with the division ID and the payment key. Set the third, optional parameter to true if you want to send your requests to the sandbox for development purpose. Optional: Set a custom user agent.
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 }
It's recommended to surround API calls with try-catch-blocks since errors are thrown as exceptions. This way they can be logged as required by the system.
The API will send you JSON as response. Use json_decode() to transform it into an object or an associative array.
Requests
There are five different requests which the client can handle for you. The required and optional parameters can be set using setters, an array or you can use a JSON string.
CreateRequest
To request a new payment or refund slip simply initiate a new CreateRequest and add the parameters. Here are three examples for a minimal payment request using setters, an array and plain json.
Payment Slips
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);
Refund Slips
This is an example for a minimal refund request. Please note that the amount is negative and must not exceed the initial payment amount. Multiple refunds for one payment up to the initial amount are possible.
use Barzahlen\Request\CreateRequest; $request = new CreateRequest(); $request->setSlipType('refund'); $request->setForSlipId('slp-1b41145c-2dd3-4e3f-bbe1-72c09fbf3f94'); $request->setTransaction('-14.95', 'EUR');
Payout Slips
This is an example for a minimal payout request.
Payout slips allow a customer to receive money and result in money being transferred from your division. They are used when paying out money that is not associated with a previous payment. When returning a portion or all of the money a customer has previously paid via Barzahlen, use refund slips.
use Barzahlen\Request\CreateRequest; $request = new CreateRequest(); $request->setSlipType('payout'); $request->setCustomerKey('LDFKHSLFDHFL'); $request->setTransaction('-14.95', 'EUR');
More parameters
You may set more parameters according to the Barzahlen API v2 Documentation.
$request->setReferenceKey('REFKEY123'); $request->setHookUrl('https://www.example.tld/barzahlen/callback'); $request->setExpiresAt('2016-04-01T12:34:56Z'); $request->setCustomerKey('customer@provider.tld'); $request->setCustomerCellPhone('01234567910'); $request->setCustomerEmail('customer@provider.tld'); $request->setCustomerLanguage('de-DE'); $request->setAddress(array( 'street_and_no' => 'Wallstr. 14a', 'zipcode' => '10179', 'city' => 'Berlin', 'country' => 'DE' )); $request->addMetadata('promo', 'summer2016');
The customer data can be set as array and the expiresAt value can be a DateTime object. Also, you can use chaining with the setters.
$expire = new \DateTime(); $expire->modify('+1 week'); $request->setExpiresAt($expire) ->setCustomer(array( 'cell_phone' => '01234567910' 'key' => 'customer@provider.tld' 'email' => 'customer@provider.tld' 'language' => 'de-DE' ));
Example Response
Representation of current slip status. (Content depends on sent parameters.)
{
"id": "slp-d90ab05c-69f2-4e87-9972-97b3275a0ccd",
"slip_type": "payment",
"division_id": "1234",
"reference_key": "O64737X",
"hook_url": "https://psp.example.com/hook",
"expires_at": "2016-01-10T12:34:56Z",
"customer": {
"key": "LDFKHSLFDHFL",
"cell_phone_last_4_digits": "6789",
"email": "john@example.com",
"language": "de-DE"
},
"checkout_token": "djF8Y2hrdHxzbHAtMTM4ZWI3NzUtOWY5Yy00NzYwLWI4ZTAtYTNlZWNmYjQ5M2IxfElBSThZMnd6SFYwbjJpMm9aSUpvREpnYnhNS3c5Z2x3elJOanlLblZJeFk9",
"metadata": {
"order_id": "1234",
"invoice_no": "A123"
},
"transactions": [
{
"id": "4729294329",
"currency": "EUR",
"amount": "123.34",
"state": "pending"
}
],
"nearest_stores": [
{
"title": "mobilcom-debitel",
"logo": {
"id": "17077"
},
"distance_m": 1160,
"address": {
"city": "Berlin",
"country": "DE",
"street_and_no": "Grunerstraße 20",
"zipcode": "10179"
},
"opening_hours": {
"days": [
{ "day": "sun", "open": [] },
{ "day": "mon", "open": [{"begin": "10:00", "end": "21:00"}] },
{ "day": "tue", "open": [{"begin": "10:00", "end": "21:00"}] },
{ "day": "wed", "open": [{"begin": "10:00", "end": "21:00"}] },
{ "day": "thu", "open": [{"begin": "10:00", "end": "21:00"}] },
{ "day": "fri", "open": [{"begin": "10:00", "end": "21:00"}] },
{ "day": "sat", "open": [{"begin": "10:00", "end": "21:00"}] }
]
}
},
{
"title": "dm-drogerie markt",
"logo": {
"id": "13045"
},
"distance_m": 1220,
"address": {
"city": "Berlin",
"country": "DE",
"street_and_no": "Alexanderplatz 1",
"zipcode": "10178"
},
"opening_hours": {
"days": [
{ "day": "sun", "open": [] },
{ "day": "mon", "open": [{"begin": "09:00", "end": "22:00"}] },
{ "day": "tue", "open": [{"begin": "09:00", "end": "22:00"}] },
{ "day": "wed", "open": [{"begin": "09:00", "end": "22:00"}] },
{ "day": "thu", "open": [{"begin": "09:00", "end": "22:00"}] },
{ "day": "fri", "open": [{"begin": "09:00", "end": "22:00"}] },
{ "day": "sat", "open": [{"begin": "09:00", "end": "22:00"}] }
]
}
},
{
"title": "dm-drogerie markt",
"logo": {
"id": "13045"
},
"distance_m": 1280,
"address": {
"city": "Berlin",
"country": "DE",
"street_and_no": "Henriette-Herz-Platz 4",
"zipcode": "10178"
},
"opening_hours": {
"days": [
{ "day": "sun", "open": [] },
{ "day": "mon", "open": [{"begin": "08:30", "end": "21:00"}] },
{ "day": "tue", "open": [{"begin": "08:30", "end": "21:00"}] },
{ "day": "wed", "open": [{"begin": "08:30", "end": "21:00"}] },
{ "day": "thu", "open": [{"begin": "08:30", "end": "21:00"}] },
{ "day": "fri", "open": [{"begin": "08:30", "end": "21:00"}] },
{ "day": "sat", "open": [{"begin": "09:00", "end": "21:00"}] }
]
}
}
]
}
UpdateRequest
To change slip parameters afterwards initiate a new UpdateRequest using the slip id. Use setters, an array or a json string to set your new or updated parameter(s). Only pending slips can be updated. For more information please read the Barzahlen API v2 Documentation.
use Barzahlen\Request\UpdateRequest; $request = new UpdateRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f'); $request->setCustomer(array( 'email' => 'customer@provider.tld', 'cell_phone' => '012345678910' )); $request->setExpiresAt('2016-01-10T12:34:56Z'); $request->setTransaction('4729294329', '150.00'); $request->setReferenceKey('NEWKEY');
The expiresAt() method can be used with a DateTime object and chaining the setters is also possible. The response will contain a json with updated information.
RetrieveRequest, ResendRequest, InvalidateRequest
The last three requests don't require any additional parameters via setters, array or json. They can be initiate with the slip id (and message type) before they're sent with the client.
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');
RetrievePdfRequest
Retrieve the slip’s PDF representation for printing. Downloading the PDF is only possible for slips in the pending state.
Note: Due to security reasons this endpoint is disabled by default and can only be enabled by Barzahlen. Please feel free to contact us if you are interested in using this feature.
use Barzahlen\Request\RetrievePdfRequest; $request = new RetrievePdfRequest('slp-f26bcd0b-556b-4285-b0b3-ba54052df97f'); // contains pdf data $response = $client->handle($request);
Webhook
When the state of a slip changes (e.g. the customer payed at a retail partner) and a hook url is set, Barzahlen will send a POST request to this hook url to let you know about the change. Initiate the Webhook class with the payment key and use it to verify the incoming request's header and body.
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 }
Support
The viacash Team will happily assist you with any problems or questions.
Send us an email to support@viafintech.com or check out our Solutions center at https://www.viafintech.com/overview-solutions/.
barzahlen/barzahlen-php 适用场景与选型建议
barzahlen/barzahlen-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 414.86k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2015 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「barzahlen」 「viafintech」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 barzahlen/barzahlen-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 barzahlen/barzahlen-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 barzahlen/barzahlen-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
TrinkPOS Sanal POS (Virtual POS) API client for PHP
Merchant-side PHP SDK for YoPay Pay Open API.
Laravel Cashier Bachs provides an expressive, fluent interface to Bachs' subscription billing services.
Standalone PayPal REST Orders v2 payment integration for Magento 2. No Magento_Paypal or SOAP/NVP dependency. Server-side redirect checkout with capture, refund, and admin transaction support.
Laravel integration for the Telebirr payment SDK
Headless PHP SDK for Ethio Telecom Telebirr payment gateway
统计信息
- 总下载量: 414.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-15