liedekef/payconiq-api-php

该包的最新版本(v3.0.0)没有提供许可证信息。

PHP的Payconiq API客户端

v3.0.0 2024-07-09 07:41 UTC

This package is auto-updated.

Last update: 2024-09-13 10:08:03 UTC


README

Payconiq

PHP的Payconiq API客户端

使用二维码接受Payconiq付款。

要求

要使用Payconiq API客户端,需要以下内容

  • Payconiq商户ID和API密钥
  • PHP >= 5.6
  • PHP cURL扩展

安装

最佳安装方法是使用Composer要求。

$ composer require liedekef/payconiq-api-php

您也可以使用git checkout或下载所有文件,然后手动包含Payconiq API客户端。

参数

以下示例中使用了以下参数

$apiKey = 'apiKey 123456'; // Used to secure request between merchant backend and Payconiq backend.
$merchantId = 'merchantid'; // payconiq merchantid (not really used, unless to verify more in notification callback)
$amount = 1000; // Transaction amount in cents
$currency = 'EUR'; // Currency
$reference = "my internal payment reference"; // an internal reference (e.g. a booking id)
      // the reference is given in the callback, allowing you to know what local payment is being handled
$callbackUrl = 'http://yoursite.com/postback'; // Callback where Payconiq needs to POST confirmation status
$returnUrl = 'http://yoursite.com/returnpage'; // Optional. the page a buyer is returned to after payment. You'll need to check
     // the payment status there

要了解更多关于Payconiq将如何、何时以及向您的callbackUrl发送POST请求的信息,请参阅开发者文档此处

用法

创建支付

use Payconiq\Client;

$payconiq = new Client($apiKey);
	
// Create a new payment
$payment = $payconiq->createPayment($amount, $currency, $reference, $callbackUrl, $returnUrl);

// Get payment id
// you may want to store this paymentId internally, to be able to do verify on callback
$paymentId = $payconiq_payment->paymentId;

// Assemble QR code content
$qrcode = $payment->_links->qrcode->href;

// Or get the href at payconiq and redirect to there, avoiding to need to generate qrcode yourself
$url = $payment->_links->checkout->href;
header("Location: $url");exit;

在测试中创建支付

use Payconiq\Client;

$payconiq = new Client($apiKey);
$payconiq->setEndpointTest();
	
// Create a new payment
$payment = $payconiq->createPayment($amount, $currency, $reference, $callbackUrl, $returnUrl);

// Get payment id
// you may want to store this paymentId internally, to be able to do verify on callback
$paymentId = $payconiq_payment->paymentId;

// Assemble QR code content
$qrcode = $payment->_links->qrcode->href;

// Or get the href at payconiq and redirect to there, avoiding to need to generate qrcode yourself
$url = $payment->_links->checkout->href;
// fix a payconiq api bug where the href-links in sandbox point to prod too
$url = str_replace("https://payconiq.com","https://ext.payconiq.com",$url);
header("Location: $url");exit;

检索支付

use Payconiq\Client;

$payconiq = new Client($apiKey);

// Retrieve a payment
$payment = $payconiq->retrievePayment($paymentId);

// use try-catch:
   try {
           $payment = $payconiq->retrievePayment($paymentId);
   } catch (Exception $e) {
           error_log("ayconiq error getting payment id $paymentId");
           return;
   }

处理通知回调

use Payconiq\Client;

$payconiq = new Client($apiKey);
$payload = @file_get_contents('php://input');
$data = json_decode($payload);
$paymentid = $data->paymentId;
$payment = $payconiq->retrievePayment($paymentid);

// verify merchantid
$payment_merchantid = $payconiq_payment->creditor->merchantId;
if ($payment_merchantid != $merchantId) {
           error_log("Payconiq wrong merchant id $payment_merchantid");
           return;
}
// get reference
$reference = $payment->reference;
// based on the reference, check the received payment id with the one you stored locally (if you did that)

// verify status and price
if ($payment->status == "SUCCEEDED" && $payment->totalAmount == $amount ) {
    // the status is ok and all is paid, update internal info based on the found reference
}