承接 speckcommerce/speck-paypal 相关项目开发

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

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

speckcommerce/speck-paypal

Composer 安装命令:

composer require speckcommerce/speck-paypal

包简介

A generic module for adding PayPal support to a ZF2 application.

关键字:

README 文档

README

A generic module for adding PayPal Payments support to a ZF2 application.

Build Status

Introduction

SpeckPaypal is a module that can be utilized outside of Speck Commerce to accept payments via paypal. This module currently supports PayPal Payments Pro and Express Checkout API Operations.

Please see: Paypal API Docs

To integrate with this module you will want to sign up for a sandbox account on Paypal. See the developer website for instructions.

This module currently supports the following calls with API version 95.0:

  • Callback
  • DoAuthorization
  • DoCapture
  • DoDirectPayment
  • DoExpressCheckoutPayment
  • DoVoid
  • GetBalance
  • GetExpressCheckoutDetails
  • GetTransactionDetails
  • RefundTransaction
  • SetExpressCheckout
  • TransactionSearch
  • UpdateRecurringPaymentsProfile
  • ManageRecurringPaymentsProfileStatus
  • CreateRecurringPaymentsProfile

Requirements

The dependencies for SpeckCommerce are set up as Git submodules so you should not hav

  • PHP 5.4+ (Note: This library should work with PHP 5.3.3+ however official support is no longer provided)
  • Zend Framework 2 (latest master)

Contributors

Community

Join us on the Freenode IRC network: #speckcommerce. Our numbers are few right now, but we're a dedicated small group working on this project full time.

Example Usage

Create a Paypal Request Object:

//setup config object
$config = array(
    'username'      => 'your_username',
    'password'      => 'your_password',
    'signature'     => 'your_signature',
    'endpoint'      => 'https://api-3t.sandbox.paypal.com/nvp' //this is sandbox endpoint
)
$paypalConfig = new \SpeckPaypal\Element\Config($config);

//set up http client
$client = new \Zend\Http\Client;
$client->setMethod('POST');
$client->setAdapter(new \Zend\Http\Client\Adapter\Curl);
$paypalRequest = new \SpeckPaypal\Service\Request;
$paypalRequest->setClient($client);
$paypalRequest->setConfig($paypalConfig);

Direct Payment Example (by default the request is sent as "Sale" which is equivalent to Authorize Capture):

$paymentDetails = new \SpeckPaypal\Element\PaymentDetails(array(
    'amt' => '10.00'
));

$payment = new \SpeckPaypal\Request\DoDirectPayment(array('paymentDetails' => $paymentDetails));
$payment->setCardNumber('4744151425799438');
$payment->setExpirationDate('112017');
$payment->setFirstName('John');
$payment->setLastName('Canyon');
$payment->setIpAddress('255.255.255.255');
$payment->setCreditCardType('Visa');
$payment->setCvv2('345');

$address = new \SpeckPaypal\Element\Address;
$address->setStreet('27 Your Street');
$address->setStreet2('Apt 23');
$address->setCity('Some City');
$address->setState('California');
$address->setZip('92677');
$address->setCountryCode('US');
$payment->setAddress($address);

$response = $paypalRequest->send($payment);

echo $response->getTransactionId();

Express Checkout Example:

It's important to understand the flow of PayPal's express checkout before attempting to use this API. Paypal Express Checkout Flow

In order to redirect the user to PayPal we first need to get a token.

$paymentDetails = new \SpeckPaypal\Element\PaymentDetails(array(
    'amt' => '20.00'
));
$express = new \SpeckPaypal\Request\SetExpressCheckout(array('paymentDetails' => $paymentDetails));
$express->setReturnUrl('http://www.someurl.com/return');
$express->setCancelUrl('http://www.someurl.com/cancel');

$response = $paypalRequest->send($express);

echo $response->isSuccess();

$token = $response->getToken();

Once you have received the token you forward the user to the paypal servers including the token you received. Refer to the documentation for URL. Once the user has completed the checkout process at PayPal they will be redirected to the URL you provided in SetExpressCheckout. When the user lands on this page you will need to make a call back to PayPal including the Token to receive the buyers payment details. You will use the payerId which is included in the response to capture the payment via DoExpressCheckoutPayment.

$details = new \SpeckPaypal\Request\GetExpressCheckoutDetails(array('token' => $token));

$response = $paypalRequest->send($details);

$payerId = $response->getPayerId();

Now that you have the payerId you can capture the payment by calling DoExpressCheckoutPayment.

//To capture express payment
$captureExpress = new \SpeckPaypal\Request\DoExpressCheckoutPayment(array(
    'token'             => $token,
    'payerId'           => $payerId,
    'paymentDetails'    => $paymentDetails
));
$response = $paypalRequest->send($captureExpress);

echo $response->isSuccess();

Transaction Search Example:

$transactionSearch new \SpeckPaypal\Request\TransactionSearch();
$transactionSearch->setStartDate('2014-06-21T00:00:00Z');

$paypalRequest = $serviceManager->get('SpeckPaypal\Service\Request');
$response = $paypalRequest->send($transactionSearch);

var_dump($response->getResults());

TODO

  • better validation based on paypal requirements (currently validation is loose)
  • refactor to relevant exception classes
  • add support for ebay items, survey questions ... and other missing payments pro apis

speckcommerce/speck-paypal 适用场景与选型建议

speckcommerce/speck-paypal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.76k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2012 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 speckcommerce/speck-paypal 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 20.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 27
  • Watchers: 12
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2012-11-07