helmutschneider/swish-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

helmutschneider/swish-php

Composer 安装命令:

composer require helmutschneider/swish-php

包简介

PHP-wrapper for the Swish api

README 文档

README

Swish-PHP is a small wrapper for the swish merchant api. See https://www.getswish.se/handel/ for more information.

Dependencies

  • php 7.3 or newer with curl & openssl
  • composer

Upgrade notes

3.0.0

  • The function createPaymentRequest now returns an object with the two properties id and paymentRequestToken. In earlier versions the id was returned directly.

Installation via git

git clone https://github.com/helmutschneider/swish-php.git
composer install

Installation via composer

composer require helmutschneider/swish-php:^3.0

Obtaining test certificates

As of 2024-09-22, a test certificate bundle (mss_test_2.0.zip) can be found by visiting: https://developer.swish.nu/documentation/environments#certificates

Begin by obtaining the SSL certificates required by Swish. The Swish server itself uses a self-signed root certificated so a CA-bundle to verify its origin is needed. You will also need a client certificate and corresponding private key so the Swish server can identify you.

As of 2024-09-22 the test certificates are called Swish_Merchant_TestCertificate_1234679304.key, Swish Merchant Test Certificate 1231181189.pem and Swish_TLS_RootCA.pem. You must concatenate Swish_Merchant_TestCertificate_1234679304.key and Swish Merchant Test Certificate 1231181189.pem together, otherwise they will not work with cURL. This bundle is your client certificate.

Usage

The client closely mirrors the swish api:

class Client
{

    /**
     * @param PaymentRequest $request
     * @return CreatePaymentRequestResponse
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws ValidationException
     */
    public function createPaymentRequest(PaymentRequest $request): CreatePaymentRequestResponse;

    /**
     * @param string $id Payment request id
     * @return PaymentRequest
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getPaymentRequest(string $id): PaymentRequest;

    /**
     * @param Refund $refund
     * @return string refund id
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws ValidationException
     */
    public function createRefund(Refund $refund): string;

    /**
     * @param string $id Refund id
     * @return Refund
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getRefund(string $id): Refund;
}

When you have the SSL certificates ready you may instantiate the client:

use HelmutSchneider\Swish\Client;
use HelmutSchneider\Swish\PaymentRequest;

// Swish CA root cert
$rootCert = 'path/to/swish-root.crt'; // forwarded to guzzle's "verify" option

// .pem-bundle containing your client cert and it's corresponding private key. forwarded to guzzle's "cert" option
// you may use an empty string for "password" if you are using the test certificates.
$clientCert = ['path/to/client-cert.pem', 'password'];

// Create a client for the production environment. To connect to the test environment
// instead, you must pass the constant Client::SWISH_TEST_URL as the third parameter.
$client = Client::make($rootCert, $clientCert);

$pr = new PaymentRequest([
    'callbackUrl' => 'https://localhost/swish',
    'payeePaymentReference' => '12345',
    'payerAlias' => '4671234768',
    'payeeAlias' => '1231181189',
    'amount' => '100',
])

$res = $client->createPaymentRequest($pr);

var_dump($res->id);

//
//  string(32) "0D3AD8F1AE484A57B82A87FAB8C602EB"
//

Notes for OSX

The bundled PHP in OSX 10.12 and earlier is not compatible with the above approach of forwarding SSL certificates. You must obtain a PHP-version that is compiled with cURL linked against OpenSSL or similar.

Run the tests

To run the tests you need certificates for the Swish test server. Place the root certificate in tests/_data/root.pem and the client certificate in tests/_data/client.pem.

vendor/bin/phpunit

helmutschneider/swish-php 适用场景与选型建议

helmutschneider/swish-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.01k 次下载、GitHub Stars 达 42, 最近一次更新时间为 2016 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 19.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 42
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 42
  • Watchers: 9
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-25