定制 twikey/twikey-api-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

twikey/twikey-api-php

Composer 安装命令:

composer require twikey/twikey-api-php

包简介

Php client to interface with the Twikey api

README 文档

README

Twikey API client for PHP

Want to allow your customers to pay in the most convenient way, then Twikey is right what you need.

Recurring or occasional payments via (Recurring) Credit Card, SEPA Direct Debit or any other payment method by bringing your own payment service provider or by leveraging your bank contract.

Twikey offers a simple and safe multichannel solution to negotiate and collect recurring (or even occasional) payments. Twikey has integrations with a lot of accounting and CRM packages. It is the first and only provider to operate on a European level for Direct Debit and can work directly with all major Belgian and Dutch Banks. However you can use the payment options of your favorite PSP to allow other customers to pay as well.

Requirements

To use the Twikey API client, the following things are required:

  • Get yourself a Twikey account.
  • PHP >= 5.6
  • Up-to-date OpenSSL (or other SSL/TLS toolkit)

Composer Installation

By far the easiest way to install the Twikey API client is to require it with Composer.

$ composer require twikey/twikey-api-php

How to create anything

The api works the same way regardless if you want to create a mandate, a transaction, an invoice or even a paylink. the following steps should be implemented:

  1. Use the Twikey API client to create or import your item.

  2. Once available, our platform will send an asynchronous request to the configured webhook to allow the details to be retrieved. As there may be multiple items ready for you a "feed" endpoint is provided which acts like a queue that can be read until empty till the next time.

  3. The customer returns, and should be satisfied to see that the action he took is completed.

Find our full documentation online on api.twikey.com.

Getting started

Initializing the Twikey API client using your preferred Http client (eg. guzzle) and configure your API key which you can find in the Twikey merchant interface.

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Twikey\Api;

$httpClient = new Client([
    'http_errors' => false,
    'debug' => false
]);

$twikey = new Twikey($httpClient,$APIKEY);

Documents

Invite a customer to sign a SEPA mandate using a specific behaviour template (ct) that allows you to configure the behaviour or flow that the customer will experience.

$invite = $twikey->document->create([
    "ct" => $ct
    "email" => "john@doe.com",
    "firstname" => "John",
    "lastname" => "Doe",
]);

After creation, the link is available for signing and ideally you store the mandatenumber for future usage (eg. sending transactions).

// store $invite->mndtId for this customer
header("Location: " . $invite->url);

Query Mandates

Query mandates with various search parameters to find specific mandates.

// Query all mandates
$mandates = $twikey->document->query();

// Query mandates with specific parameters
$mandates = $twikey->document->query([
    'email' => 'john@doe.com',
    'state' => 'SIGNED',
    'customerNumber' => 'CUST123'
]);

Feed

$twikey->document->feed(new class implements DocumentCallback {
   function handleNew($update)
   {
       print("New " . $update->Mndt->MndtId . ' @ '. $update->EvtTime . "\n");
   }

   function handleUpdate($update)
   {
       $rsn = $update->AmdmntRsn->Rsn;
       print("Update: " . $update->Mndt->MndtId . ' -> '. $rsn . ' @ '. $update->EvtTime . "\n");
   }

   function handleCancel($update)
   {
       $rsn = $update->CxlRsn->Rsn;
       print("Cancel: " . $update->OrgnlMndtId . ' -> '. $rsn . ' @ '. $update->EvtTime . "\n");
   }
}
);

Transactions

Send new transactions and act upon feedback from the bank.

$invite = $twikey->transaction->create([
   "mndtId" => "CORERECURRENTNL16318",
   "message" => "Test Message",
   "ref" => "Merchant Reference",
   "amount" => 10.00, // 10 euro
   "place" => "Here"
]);

Feed

$count = $twikey->transaction->feed(new class implements TransactionCallback{
   public function handle($transaction)
   {
       print("Transaction " . $transaction->id . ' @ '. $transaction->date . ' has '. $transaction->state . "\n");
   }
});

Webhook

When wants to inform you about new updates about documents or payments a webhookUrl specified in your api settings be called.

$queryString = decode($_SERVER['QUERY_STRING']);
$signatureHeader = $_SERVER['HTTP_X_SIGNATURE'];

Twikey::validateWebhook($APIKEY, "abc=123&name=abc", $queryString, $signatureHeader);

API documentation

If you wish to learn more about our API, please visit the Twikey Api Page. API Documentation is available in English.

Want to help us make our API client even better?

Want to help us make our API client even better? We take pull requests.

Support

Contact: www.twikey.com

twikey/twikey-api-php 适用场景与选型建议

twikey/twikey-api-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 151.52k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2021 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「payment」 「payments」 「service」 「gateway」 「ideal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 twikey/twikey-api-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 twikey/twikey-api-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 twikey/twikey-api-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 151.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-17