定制 seberm/paypal-component 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

seberm/paypal-component

Composer 安装命令:

composer require seberm/paypal-component

包简介

PayPal basic library and Nette component

README 文档

README

Installation

Simplest installation is using composer:

$ composer require seberm/paypal-component

or manually you can edit composer.json:

"require": {
        "seberm/paypal-component": "1.0.*"
}

Configuration

A) Using DI Extension (Nette 2.1+)

Add following lines into your config.neon file.

parameters: ...

---------------------------
paypal:
    api:
       username: 'seberm_1332081338_biz_api1.gmail.com'
       password: '1332081363'
       signature: 'AWiH1IO0zFZrEQbbn0JwDZHbWukIAebmYjpOylRCqBGGgztea2bku.N4'
    sandbox: true # default is false

extensions:
    paypal: Seberm\DI\PayPalExtension
---------------------------

php:
    date.timezone: Europe/Prague
    ...

More about DI container extensions you can find here: https://doc.nette.org/en/2.3/di-extensions

B) Manually throught factories

Alternatively you can configure component via factories.

parameters:
    paypal:
        api:
            username: 'seberm_1332081338_biz_api1.gmail.com'
            password: '1332081363'
            signature: 'AWiH1IO0zFZrEQbbn0JwDZHbWukIAebmYjpOylRCqBGGgztea2bku.N4'
        sandbox: true

factories:
    paypalOrderButton:
        implement: Seberm\Components\PayPal\Buttons\IOrderFactory
        setup:
            - setCredentials(%paypal.api%)
            - setSandBox(%paypal.sandbox%)

Example of a Presenter

Firstly, you have to get IOrderFactory object.

Getting IOrderFactory using DI extensions (method A)

/** @var \Seberm\Components\PayPal\Buttons\IOrderFactory @inject */
public $factory;

Getting IOrderFactory using nette factories (method B)

/** @var \Seberm\Components\PayPal\Buttons\IOrderFactory $factory */
public $factory;

/**
 * @param \Seberm\Components\PayPal\Buttons\IOrderFactory $factory
 */
public function injectFactory(\Seberm\Components\PayPal\Buttons\IOrderFactory $factory)
{
    $this->factory = $factory;
}

Following code will be the same for both methods.

/** @var \Seberm\Components\PayPal\Buttons\Order */
private $orderButton;

public function startup()
{
    parent::startup();

    $this->orderButton = $this->factory->create();
    $this->orderButton->setSessionSection($this->session->getSection('paypal'));
    $this->orderButton->onSuccessPayment[] = array($this, 'successPayment');
}

/**
 * Creates new button control. After that you can load this control in template
 * via {control paypalButton}.
 * @return Seberm\Components\PayPal\Buttons\Order
 */
protected function createComponentPaypalButton()
{
    $control = $this->orderButton;
    $control->setCurrencyCode(\Seberm\PayPal\API\API::CURRENCY_EURO);
    $control->onConfirmation[] = array($this, 'confirmOrder');
    $control->onError[] = array($this, 'errorOccurred');
    $control->onCancel[] = array($this, 'canceled');

    // It is possible to set shipping
    $button->shipping = 4.3;

    // or set a tax
    $button->tax = 3.1;

    $price = 56; // In Euro in this example

    $control->addItemToCart('Product A', 'A - Product description', $price);
    $control->addItemToCart('Product B', 'B - Product description', 123);

    return $control;
}
Don't forget to define callback methods

This method is called after successful confirmation. It has one argument $data.

public function successPayment($data) {
    /**
     * Here you can proccess information about user. For example save him to the
     * database...
     */

     $payerID = $data->payerID;
     $firstName = $data->firstName;
     $lastName = $data->lastName;
     $email = $data->email;

     // See dump($data);
}

Following method is called if some error occures (for example error in communication). It receives an array of errors.

public function errorOccurred($errors)  { ... }
// It is called if payment inicialization succeeds
public function confirmOrder($data) {
    /**
     * Here you can do some checks of the order data. If everything is ok,
     * you can confirm the order with confirmExpressCheckout() method.
     */
    ...
    $this->orderButton->confirmExpressCheckout();
}

public function canceled($data)       { ... } // Called if user cancels his order

Adding PayPal button to a template

Add following control macro where you want to have your PayPal button.

{control paypalButton}

seberm/paypal-component 适用场景与选型建议

seberm/paypal-component 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 904 次下载、GitHub Stars 达 15, 最近一次更新时间为 2014 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-2-Clause-FreeBSD
  • 更新时间: 2014-02-19