flame/paypal-component

PayPal basic API written in Nette

dev-master 2013-04-06 21:22 UTC

This package is not auto-updated.

Last update: 2024-11-09 13:48:47 UTC


README

##Usage

###Config

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

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

			# This option cause that you're not redirected back on your page for payment confirmation but you confirm payment directly on PayPal page
			#- setRedirectToConfirm(false)

###Presenter

/**
 * @var \Flame\Components\PayPal\Buttons\IOrderFactory $orderFactory
 */
private $orderFactory;

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


/**
 * @param \Flame\Components\PayPal\Buttons\IOrderFactory $orderFactory
 */
public function injectOrderFactory(\Flame\Components\PayPal\Buttons\IOrderFactory $orderFactory)
{
	$this->orderFactory = $orderFactory;
}

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

	$this->orderButton = $this->orderFactory->create();
	$this->orderButton->setSessionSection($this->session->getSection('paypal'));
	$this->orderButton->onSuccessPayment[] = \Nette\Callback::create($this, 'processPayment');
}

/**
 * @return Flame\Components\PayPal\Buttons\Order
 */
protected function createComponentPaypalButton()
{

	$control = $this->orderButton;
	$control->setCurrencyCode(\Flame\PayPal\API\API::CURRENCY_EURO);
	$control->onConfirmation[] = \Nette\Callback::create($this, 'confirmOrder');
	$control->onError[] = \Nette\Callback::create($this, 'errorOccurred');

	//$tourModel is instance of PRODUCT
	$control->addItemToCart(
		$tourModel['name'], \Nette\Utils\Strings::substring($tourModel['desc'], 0, 25), $tourModel['price']
	);

	return $control;
}