承接 multisafepay/php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

multisafepay/php-sdk

Composer 安装命令:

composer require multisafepay/php-sdk

包简介

MultiSafepay PHP SDK

README 文档

README

MultiSafepay PHP SDK

Build Codecov Latest stable version Total downloads License

About MultiSafepay

MultiSafepay is a Dutch payment services provider, which takes care of contracts, processing transactions, and collecting payment for a range of local and international payment methods. Start selling online today and manage all your transactions in one place!

Installation

Run the following composer command:

composer require multisafepay/php-sdk

WARNING! This SDK does not have a direct dependency on Guzzle or cURL. Instead, it uses the PSR-18 client abstraction and PSR-17 factory abstraction. This lets you choose which PSR-7 implementation and HTTP client to use. You can replace all clients without any side effects.

If you don't have a client implementation installed, run:

composer require guzzlehttp/guzzle

If you don't have a factory implementation installed, run:

composer require http-interop/http-factory-guzzle

You should now have installed:

Getting started

Use Composer autoloader to automatically load class dependencies:

require 'vendor/autoload.php';

Next, instantiate the SDK with your site API key and a flag to identify whether this is the live environment or testing environment.

$yourApiKey = 'your-api-key';
$isProduction = false;
$multiSafepaySdk = new \MultiSafepay\Sdk($yourApiKey, $isProduction);

From the SDK, you can get various managers:

$multiSafepaySdk->getTransactionManager();
$multiSafepaySdk->getGatewayManager();
$multiSafepaySdk->getPaymentMethodManager();
$multiSafepaySdk->getIssuerManager();
$multiSafepaySdk->getCategoryManager();
$multiSafepaySdk->getTokenManager();
$multiSafepaySdk->getApiTokenManager();

The transaction manager is the most important, because it lets you create orders and refunds.

use MultiSafepay\ValueObject\Customer\Country;
use MultiSafepay\ValueObject\Customer\Address;
use MultiSafepay\ValueObject\Customer\PhoneNumber;
use MultiSafepay\ValueObject\Customer\EmailAddress;
use MultiSafepay\ValueObject\Amount;
use MultiSafepay\ValueObject\Currency;
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\CustomerDetails;
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\PluginDetails;
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\PaymentOptions;
use MultiSafepay\Api\Transactions\OrderRequest;

$yourApiKey = 'your-api-key';
$isProduction = false;
$multiSafepaySdk = new \MultiSafepay\Sdk($yourApiKey, $isProduction);

$orderId = (string) time();
$description = 'Order #' . $orderId;
$amount = new Amount(2000); // Amount must be in cents!!
$currency = new Currency('EUR');

$address = (new Address())
    ->addStreetName('Kraanspoor')
    ->addStreetNameAdditional('(blue door)')
    ->addHouseNumber('39')
    ->addZipCode('1033SC')
    ->addCity('Amsterdam')
    ->addState('Noord Holland')
    ->addCountry(new Country('NL'));

$customer = (new CustomerDetails())
    ->addFirstName('John')
    ->addLastName('Doe')
    ->addAddress($address)
    ->addEmailAddress(new EmailAddress('noreply@example.org'))
    ->addPhoneNumber(new PhoneNumber('0208500500'))
    ->addLocale('nl_NL');

$pluginDetails = (new PluginDetails())
    ->addApplicationName('My e-commerce application')
    ->addApplicationVersion('0.0.1')
    ->addPluginVersion('1.1.0');

$paymentOptions = (new PaymentOptions())
    ->addNotificationUrl('http://www.example.com/client/notification?type=notification')
    ->addRedirectUrl('http://www.example.com/client/notification?type=redirect')
    ->addCancelUrl('http://www.example.com/client/notification?type=cancel')
    ->addCloseWindow(true);

$orderRequest = (new OrderRequest())
    ->addType('redirect')
    ->addOrderId($orderId)
    ->addDescriptionText($description)
    ->addAmount($amount)
    ->addCurrency($currency)
    ->addGatewayCode('IDEAL')
    ->addCustomer($customer)
    ->addDelivery($customer)
    ->addPluginDetails($pluginDetails)
    ->addPaymentOptions( $paymentOptions);

$transactionManager = $multiSafepaySdk->getTransactionManager()->create($orderRequest);
$transactionManager->getPaymentUrl();

Example refund:

// Refund example.
use MultiSafepay\Api\Transactions\RefundRequest;
use MultiSafepay\ValueObject\Amount;
use MultiSafepay\ValueObject\Currency;

$yourApiKey = 'your-api-key';
$isProduction = false;
$multiSafepaySdk = new \MultiSafepay\Sdk($yourApiKey, $isProduction);

$orderId = XXXXX;  // The order ID of a previously completed transaction
$refundAmount = new Amount(2000);
$refundCurrency = new Currency('EUR');
$transactionManager = $multiSafepaySdk->getTransactionManager();
$transaction = $transactionManager->get($orderId);
$transactionManager->refund($transaction, (new RefundRequest())->addAmount($refundAmount)->addCurrency($refundCurrency));

For examples of building full requests, see USAGE.md and the functional tests in tests/Functional/Api/Transactions.

Advanced usage: Strict mode

Strict mode:

  • Adds additional validations on top of various API requests and responses.
  • Validation errors throw an exception, which you need to handle.
  • It is enabled in tests.

Non-strict mode (default) skips some validation errors.

Example: If there is a mismatch between the number of decimal places of the total amount of the items in the ShoppingCart object and your ecommerce platform, strict mode throws an \MultiSafepay\Exception\InvalidTotalAmountException exception.

Code quality checks

The following checks are in place to maintain code quality:

  • PHP CodeSniffer (via ./vendor/bin/phpcs --standard=phpcs.ruleset.xml .)
    • PSR-2
    • Object Calisthenics
  • PHPUnit tests (via ./vendor/bin/phpunit)
    • Unit tests
    • Integration tests
    • Functional tests

Testing

  • Unit tests work without the API or any dependencies (tests/Unit)
  • Integration tests work without the API but have dependencies (tests/Integration)
  • Functional tests work with the live API (tests/Functional) – API key required

Unit tests

To run unit tests from this package:

  1. Clone this repository.
  2. To install all dependencies, run composer install
  3. Run PHPUnit with the following command: ./vendor/bin/phpunit tests/Unit

Functional tests

To run functional tests from this package:

  1. Clone this repository.
  2. To install all dependencies, run composer install.
  3. Copy .env.php.example to .env.php and add your site API key.
  4. Run PHPUnit with the following command: ./vendor/bin/phpunit tests/Functional

Mocking the API for unit and integration tests

Unit and integration tests run without the API, which means that the client is mocking all data calls. To do this, the tests/fixture-data folder contains JSON files to spoof calls. To fill this folder with real data, make sure you have a valid .env.php file, and then use the following command:

php tests/generateApiMocks.php

This commits all generated JSON files into git, so that they serve as fixtures. Files that are not used in tests don't need to be generated.

Support

Create an issue on this repository or email integration@multisafepay.com

Contributors

If you create a pull request to suggest an improvement, we'll send you some MultiSafepay swag as a thank you!

License

Open Software License (OSL 3.0)

Want to be part of the team?

Are you a developer interested in working at MultiSafepay? Check out our job openings and feel free to get in touch!

multisafepay/php-sdk 适用场景与选型建议

multisafepay/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.03M 次下载、GitHub Stars 达 14, 最近一次更新时间为 2020 年 06 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.03M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 11
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 7
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: OSL-3.0
  • 更新时间: 2020-06-08