dwmsw/sagepay 问题修复 & 功能扩展

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

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

dwmsw/sagepay

Composer 安装命令:

composer require dwmsw/sagepay

包简介

Sagepay Direct V3 Wrapper

README 文档

README

Build Status Code Climate Test Coverage

Description

dwmsw/sagepay is a library for interacting with the Sagepay Direct v3.00 protocol

It aims to make interacting with Sagepay as easy as possible and is available as a composer package on packagist

This wrapper doesn't include any database implementations, it is purely here to make interacting with the Sagepay API easier and to add a level of validation. All methods that send the data to Sagepay will return the response to you in an associative array, with nothing added or removed.

It has been built this way as to not restrict developers to certain database implementations or structures. We prefer for you to be able to use the data however you like.

##Installation

Installing via composer is the best way. Run the following from the CLI

composer require dwmsw/sagepay

What is implemented?

  • Payments (with or without tokens)
  • Deferred Payments w/ release
  • Discounts
  • Refunds
  • 3D Secure

Basic Usage

Payment

// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();

// New Basket instance
$basket = new dwmsw\sagepay\Basket();
// Add an item to the basket
$basket->addItem(new dwmsw\sagepay\Item('Test Item', 30.00, 6, 1));
// Add another item to the basket
$basket->addItem(new dwmsw\sagepay\Item('Test Item Two', 30.00, 6, 2));
// Add a discount
$basket->addDiscount(new dwmsw\sagepay\Discount(50.00, 'This is a discount'));

// Set the Basket
$sagepay->setBasket($basket);

// Set up the config
$sagepay->setConnectionMode(CONNECTION MODE TEST/LIVE);
$sagepay->setVendorName(YOUR VENDOR NAME);
$sagepay->setCurrency('GBP');
$sagepay->setApplyAvsCv2(1);
$sagepay->setApply3dSecure(0);
$sagepay->setGiftAid(0);

$vendorTxCode = md5(rand(1, 1000));

// TX Specific bits
$sagepay->setVendorTxCode($vendorTxCode);
$sagepay->setDescription('Test Payment');
$sagepay->setCustomerEmail('daryll@digitalwebmedia.co.uk');

// Set up addresses
$BillingAddress = new dwmsw\sagepay\Address();
$BillingAddress->setName('Daryll', 'Doyle');
$BillingAddress->setPhone('46554789658');
$BillingAddress->setAddress('88', 'Test Address', 'Town', 'GB', '412');

// Set Addresses into the class
$sagepay->setBillingAddress($BillingAddress);
// Delivery Address can be a different instance of address if needed
$sagepay->setDeliveryAddress($BillingAddress);

// New card instance
$card = new dwmsw\sagepay\Card();
// Card details 
$card->setCardHolder('Mr D Doyle');
$card->setCardType('VISA');
$card->setCardNumber('4929000000006');
$card->setStartDate(false);
$card->setExpiryDate('1216');
$card->setCV2('123');

$sagepay->setCard($card);

$output = $sagepay->register('PAYMENT');

// Do whatever you want with $output

To use tokens with payments, you'll initially need to pass the following in your setup:

$sagepay->setCreateToken(1);

This will tell sagepay to return you a token when payments are successful. You can then use this token, to make further payments.

To make a payment using a token, you don't enter the card details, but instead use the following:

// New card instance
$card = new dwmsw\sagepay\Card();
$card->setToken('TOKEN');
$card->setCV2('CV2');

$sagepay->setCard($card);

When using a token, the class automatically sets StoreToken to 1 to persist the token. Although I will probably add an option to change this at some point!

DEFERRED

// As above, but use the following line
$output = $sagepay->register('DEFERRED');

RELEASE

// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// Make the release
$output = $sagepay->release('VPSTxId', 'SecurityKey', 'vendorTxCode', 'TxAuthNo', 'AMOUNT TO RELEASE');
    
// Do whatever with $output

REFUND

// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// Make the refund
$output = $sagepay->refund('NEWvendorTxCode', 'AMOUNT TO REFUND', 'OLDVPSTxId', 'OLDvendorTxCode', 'OLDSecurityKey', 'OLDTxAuthNo', 'Refund Message');
    
// Do whatever with $output

3D Secure

// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
$sagepay->setConnectionMode('test');

// Send the output back to Sagepay
$output = $sagepay->threeDResponse($_POST['MD'], $_POST['PaRes']);

To Do

  • Paypal Integration

Getting Involved

  • Open an issue with a feature you'd like
  • Make a PR
  • Write any tests that may be missing!

dwmsw/sagepay 适用场景与选型建议

dwmsw/sagepay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.7k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2014 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dwmsw/sagepay 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2014-11-06