2017 © Pedro Peláez
 

library paypal-component

PayPal basic library and Nette component

image

seberm/paypal-component

PayPal basic library and Nette component

  • Thursday, April 28, 2016
  • by seberm
  • Repository
  • 3 Watchers
  • 15 Stars
  • 439 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 4 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

PayPal Component

Installation

Simplest installation is using composer:, (*1)

$ composer require seberm/paypal-component

or manually you can edit composer.json:, (*2)

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

Configuration

A) Using DI Extension (Nette 2.1+)

Add following lines into your config.neon file., (*3)

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, (*4)

B) Manually throught factories

Alternatively you can configure component via factories., (*5)

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., (*6)

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., (*7)

/** @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., (*8)

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., (*9)

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., (*10)

{control paypalButton}

The Versions

28/04 2016

dev-master

9999999-dev https://github.com/seberm/nette-paypal

PayPal basic library and Nette component

  Sources   Download

BSD-2-Clause-FreeBSD

The Requires

 

The Development Requires

api component payments paypal nette

28/04 2016

1.0.3

1.0.3.0 https://github.com/seberm/nette-paypal

PayPal basic library and Nette component

  Sources   Download

BSD-2-Clause-FreeBSD

The Requires

 

The Development Requires

api component payments paypal nette

29/03 2015

1.0.2

1.0.2.0 https://github.com/seberm/nette-paypal

PayPal basic library and Nette component

  Sources   Download

BSD-2-Clause-FreeBSD

The Requires

  • php >=5.3.2
  • ext-curl *

 

The Development Requires

api component payments paypal nette

29/03 2015

1.0.1-beta

1.0.1.0-beta https://github.com/seberm/nette-paypal

PayPal basic API written in Nette

  Sources   Download

BSD-2-Clause-FreeBSD

The Requires

  • php >=5.3.2
  • ext-curl *

 

The Development Requires

api component payments paypal nette

06/04 2013

1.0.0

1.0.0.0 https://github.com/flame-org/PayPal-Component

PayPal basic API written in Nette

  Sources   Download

BSD-2-Clause-FreeBSD

The Requires

 

The Development Requires

api payments paypal nette

06/08 2012

1.0.0-beta

1.0.0.0-beta https://github.com/seberm/nette-paypal

PayPal basic API written in Nette

  Sources   Download

GPLv2 GPLv3

api payments paypal nette

21/07 2012

1.0.0-alpha

1.0.0.0-alpha https://github.com/seberm/nette-paypal

PayPal basic API written in Nette

  Sources   Download

GPLv2 GPLv3

api payments paypal nette