Skip to content

Commit

Permalink
Working web checkout Facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
joselfonseca committed Aug 24, 2015
1 parent 6dc3eeb commit f171529
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
composer.phar
composer.lock
/nbproject
/site
61 changes: 37 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
{
"name": "anvarco/payulatam",
"description": "Payulatam form laravel provides an expressive, fluent interface to PayuLatam subscription billing services.",
"version": "0.0.3-dev",
"type": "project",
"require": {
"php": ">=5.5.9",
"anvarco/sdkpayu": "1.0.*",
"laravel/framework": "5.*"
},
"license": "MIT",
"authors": [
{
"name": "AnvarStudios.CO Labs",
"email": "[email protected]",
"homepage": "http://www.anvarstudios.co",
"role": "Developer"
}
],
"support": {
"name": "anvarco/payulatam",
"description": "Payulatam form laravel provides an expressive, fluent interface to PayuLatam subscription billing services.",
"version": "0.0.3-dev",
"type": "project",
"require": {
"php": ">=5.5.9"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"orchestra/testbench": "~3.1"
},
"license": "MIT",
"authors": [
{
"name": "AnvarStudios.CO Labs",
"email": "[email protected]",
"wiki": "https://github.com/anvarstudios/LaravelPayuLatam/wiki"
"homepage": "http://www.anvarstudios.co",
"role": "Developer"
},
"autoload": {
"psr-4": {
"AnvarCO\\PayuLatam\\": "src/"
}
{
"name": "Jose Luis Fonseca",
"email": "[email protected]",
"homepage": "https://www.josefonseca.me",
"role": "Developer"
}
],
"support": {
"email": "[email protected]",
"wiki": "https://github.com/anvarstudios/LaravelPayuLatam/wiki"
},
"autoload": {
"psr-4": {
"AnvarCO\\PayuLatam\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"AnvarCO\\PayuLatam\\Tests\\": "tests/"
}
}
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
37 changes: 37 additions & 0 deletions src/Form/Builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace AnvarCO\PayuLatam\Form;


use AnvarCO\PayuLatam\WebCheckoutData;

/**
* Class Builder
* @package AnvarCO\PayuLatam\Form
* @author Jose Luis Fonseca <[email protected]>
*/
class Builder {

/**
* @var WebCheckoutData
*/
private $payu;

/**
* @param WebCheckoutData $payu
*/
public function __construct(WebCheckoutData $payu)
{
$this->payu = $payu;
}

/**
* ger the form based on the theme in config
* @return string
*/
public function getForm()
{
return view('payulatam::templates.'.config('payulatam.theme','bootstrap'))->with($this->payu->toArray())->render();
}

}
54 changes: 19 additions & 35 deletions src/PayuLatamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,29 @@ class PayuLatamServiceProvider extends ServiceProvider
*/
public function boot()
{

$this->loadViewsFrom(realpath(__DIR__.'/views'), 'payulatam');
$this->loadTranslationsFrom(__DIR__.'/lang', 'payulatam');
$this->setupRoutes($this->app->router);

$this->loadViewsFrom(realpath(__DIR__ . '/views'), 'payulatam');
$this->loadTranslationsFrom(__DIR__ . '/lang', 'payulatam');
$this->setupRoutes($this->app->router);
// this for config
$this->publishes([
__DIR__.'/config/payulatam.php' => config_path('payulatam.php'),
__DIR__ . '/config/payulatam.php' => config_path('payulatam.php'),
]);



}

/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function setupRoutes(Router $router)
{
$router->group(['namespace' => 'AnvarCO\PayuLatam\Http\Controllers'], function ($router) {
require __DIR__ . '/Http/routes.php';
});
}

/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function setupRoutes(Router $router)
{

$router->group(['namespace' => 'AnvarCO\PayuLatam\Http\Controllers'], function($router)
{
require __DIR__.'/Http/routes.php';
});
}

/**
* Register the application services.
Expand All @@ -49,18 +45,6 @@ public function setupRoutes(Router $router)
*/
public function register()
{

$this->registerPayuLatam();
config([
'config/contact.php',
]);

$this->app->bind('WebCheckoutData', 'AnvarCO\PayuLatam\WebCheckoutData');
}

private function registerPayuLatam()
{
$this->app->bind('payulatam',function($app){
return new Payulatam($app);
});
}
}
173 changes: 173 additions & 0 deletions src/WebCheckoutData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

namespace AnvarCO\PayuLatam;


/**
* Class WebCheckoutData
* @package AnvarCO\PayuLatam
* @author Jose Luis Fonseca <[email protected]>
*/
class WebCheckoutData
{

/**
* @var
*/
private $merchantId;
/**
* @var
*/
private $apiKey;
/**
* @var
*/
private $apiLogin;
/**
* @var
*/
private $lang;
/**
* @var
*/
private $currency;
/**
* @var bool
*/
private $test = true;
/**
* @var
*/
private $responseUrl;
/**
* @var
*/
private $confirmationUrl;
/**
* @var
*/
private $buyerEmail;
/**
* @var
*/
private $description;
/**
* @var
*/
private $referenceCode;
/**
* @var
*/
private $amount;
/**
* @var
*/
private $tax;
/**
* @var
*/
private $taxReturnBase;
/**
* @var null
*/
private $signature = null;
/**
* @var string
*/
private $url = "https://stg.gateway.payulatam.com/ppp-web-gateway/";

/**
*
*/
public function __construct()
{
$this->setVariables();
}

/**
* Set the variables to generate the form
* @param $buyerEmail
* @param $description
* @param $referenceCode
* @param $amount
* @param int $tax
* @param int $taxReturnBase
* @return $this
*/
public function init($buyerEmail, $description, $referenceCode, $amount, $tax = 0, $taxReturnBase = 0)
{
$this->buyerEmail = $buyerEmail;
$this->description = $description;
$this->referenceCode = $referenceCode;
$this->amount = $amount;
$this->tax = $tax;
$this->taxReturnBase = $taxReturnBase;

return $this;
}

/**
* Generate the signature and return the object for a builder
* @return $this
*/
public function process()
{
$this->setSignature();

return $this;
}

/**
* Get the data required for PayU Web checkout as array
* @return array
*/
public function toArray()
{
return [
'merchantId' => $this->merchantId,
'accountId' => $this->merchantId,
'description' => $this->description,
'referenceCode' => $this->referenceCode,
'currency' => $this->currency,
'amount' => $this->amount,
'tax' => $this->tax,
'taxReturnBase' => $this->taxReturnBase,
'signature' => $this->signature,
'isTest' => (int)$this->test,
'buyerEmail' => $this->buyerEmail,
'responseUrl' => $this->responseUrl,
'confirmationUrl' => $this->confirmationUrl,
'url' => $this->url
];
}

/**
* Generate the signature based in the given data
* @return $this
*/
protected function setSignature()
{
$this->signature = md5($this->apiKey . '~' . $this->merchantId . '~' . $this->referenceCode . '~' . $this->amount . '~' . $this->currency);

return $this;
}

/**
* Set the initial variables from config
*/
private function setVariables()
{
$this->merchantId = config('payulatam.merchantId', '123');
$this->apiKey = config('payulatam.apiKey', '123');
$this->apiLogin = config('payulatam.apiLogin', '123');
$this->lang = config('payulatam.language', 'es');
$this->currency = config('payulatam.currency', 'COP');
$this->test = config('payulatam.test', true);
$this->responseUrl = config('payulatam.responseUrl', '');
$this->confirmationUrl = config('payulatam.confirmationUrl', '');
if (empty($this->test)) {
$this->url = "https://gateway.payulatam.com/ppp-web-gateway/";
}
}

}
Loading

0 comments on commit f171529

Please sign in to comment.