issei-m/spike-php 问题修复 & 功能扩展

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

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

issei-m/spike-php

最新稳定版本:v1.0-BETA5

Composer 安装命令:

composer require issei-m/spike-php

包简介

The client of https://spike.cc REST api for PHP.

README 文档

README

[ABANDONED]

This project is already abandoned due to SPIKE payment service close, and you can no longer access to their api endpoint anymore.

Latest release: v1.0-BETA5

The client of https://spike.cc REST api for PHP (5.4+, 7+, HHVM).

Basic Usage

First, initialize the Spike object with your api secret key. It's the entry point for accessing the all api interfaces:

$spike = new \Issei\Spike\Spike('your_api_secret_key');

Create a new charge

To create a new charge, you have to build a ChargeRequest object. It can be specified card token, amount, currency and some related products. Next, call charge() method with it. If charge succeeded this method will return the new Charge object generated by REST api:

// The token's id is retrieved by SPIKE Checkout (client side script) usually.
$token = new \Issei\Spike\Model\Token('tok_xxxxxxxxxxxxxxxxxxxxxxxx');

$request = new \Issei\Spike\ChargeRequest();
$request
    ->setToken($token)
    ->setAmount(123.45, 'USD')
    ->setCapture(true) // If you set false, you can delay capturing.
;

$product = new \Issei\Spike\Model\Product('my-product-00001');
$product
    ->setTitle('Product Name')
    ->setDescription('Description of Product.')
    ->setPrice(123.45, 'USD')
    ->setLanguage('EN')
    ->setCount(3)
    ->setStock(97)
;

// The product can be added any times.
$request->addProduct($product);

/** @var $createdCharge \Issei\Spike\Model\Charge */
$createdCharge = $spike->charge($request);

Tips: You can pass the Token's id directly instead of generating the new Token object:

$request->setToken('tok_xxxxxxxxxxxxxxxxxxxxxxxx');

NOTE: If you want to know how to get a card token, read Request a token section.

Find a charge

Call getCharge() method with charge id:

/** @var $charge \Issei\Spike\Model\Charge */
$charge = $spike->getCharge('20150101-100000-xxxxxxxxxx');

Capture the charge

If you have a charge which has not been captured, you can use capture() method to capture it:

/** @var $charge \Issei\Spike\Model\Charge */
$capturedCharge = $spike->capture($charge);

Refund the charge

Call refund() method with the Charge object that you want to refund:

/** @var $charge \Issei\Spike\Model\Charge */
$refundedCharge = $spike->refund($charge);

Tips: You can pass the Charge's id directly instead of generating/retrieving the Charge object:

$refundedCharge = $spike->refund('20150101-100000-xxxxxxxxxx');

Retrieve the all charges

Call getCharges() method. it returns an array containing the Charge objects.

/** @var $charges \Issei\Spike\Model\Charge[] */
$charges = $spike->getCharges();

Paging

You can specify the limit of number of records at 1st argument (10 records by default):

$charges = $spike->getCharges(5);

If you pass a Charge object (or ID as a string directly) into 2nd argument, you can retrieve charges that older than (passed charge is NOT included to list):

$nextCharges = $spike->getCharges(5, $charges[count($charges) - 1]);

At 3rd argument, you can also specify the charge (or ID as a string directly) object if you want to retrieve charges that newer than (passed charge is NOT included to list):

$nextCharges = $spike->getCharges(5, $charges[count($charges) - 1], ...);

Request a token

If you have contracted with https://spike.cc to request a new token, you can get a new token by requestToken() method with TokenRequest:

$request = new \Issei\Spike\TokenRequest();
$request
    ->setCardNumber('4444333322221111')
    ->setExpirationMonth(12)
    ->setExpirationYear(19)
    ->setHolderName('Taro Spike')
    ->setSecurityCode('123')
    ->setCurrency('JPY')
    ->setEmail('test@example.jp')
;

/** @var $charge \Issei\Spike\Model\Token */
$token = $spike->requestToken($request);

Of course, you can create a new charge with it:

$request = new \Issei\Spike\ChargeRequest();
$request
    ->setToken($token)
    // ...
;

/** @var $charge \Issei\Spike\Model\Charge */
$charge = $spike->charge($request);

Find a token

Call getToken() method with token id:

/** @var $token \Issei\Spike\Model\Token */
$token = $spike->getToken('tok_xxxxxxxxxxxxxxxxxxxxxxxx');

Installation

Use Composer to install the package:

$ composer require issei-m/spike-php

Contributing

  1. Fork it
  2. Create your feature branch
  3. Commit your change and push it
  4. Create a new pull request

issei-m/spike-php 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-09