Skip to content

Commit

Permalink
Merge pull request anvargear#2 from joselfonseca/master
Browse files Browse the repository at this point in the history
Web Checkout Facilities
  • Loading branch information
Andres Felipe Vasquez committed Sep 7, 2015
2 parents 6dc3eeb + 733bb12 commit 3755443
Show file tree
Hide file tree
Showing 24 changed files with 650 additions and 141 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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# PayuLatam for Laravel



## Introduction

Documentation for PayuLatam provides an expressive, fluent interface to [PayuLatam](https://secure.payulatam.com/online_account/507740/create_account.html) subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantities", cancellation grace periods, and even generate invoice PDFs.
Expand Down
60 changes: 36 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
{
"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.",
"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/"
}
}
}
73 changes: 73 additions & 0 deletions docs/webcheckout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Migration

Please copy the migration from the migrations folder in this package to your app and run `php artisan:migrate`

# Web Checkout Class

This class will alow you to generate the signature and will hold all the information needed to build a form for the web checkout endpoint in PayU Latam.

## Env file

You need to set the following varibles in your .env file

```bash
PAYU_MERCHANT_ID=500238
PAYU_ACCOUNT=509171
PAYU_API_KEY=6u39nqhq8ftd0hlvnjfs66eh8c
PAYU_API_LOGIN=11959c415b33d0c
PAYU_LANG=es
PAYU_RESPONSE_URL=http://example.com/payu/response
PAYU_CONFIRMATION_URL=http://example.com/payu/confirmation
```

## Example

```php
use AnvarCO\PayuLatam\Form\Builder as PayuLatamForm;

$webCheckout = app('WebCheckoutData');
/**
* @param $buyerEmail
* @param $description
* @param $referenceCode
* @param $amount
* @param int $tax
* @param int $taxReturnBase
* @return $this
*/
$webCheckout->init('[email protected]', 'Description', 'Reference', 35000, 0, 0)->process();
$form = new PayuLatamForm($webCheckout);
echo $form->getForm();
```
Don't forget to add this endpoint to the except property in the VerifyCsfrToken Middleware

```
'payu/confirmation'
```

Something like this

```php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'payu/confirmation'
];
}

```

#Events

The package fires 2 events in the confirmation post request `AnvarCO\PayuLatam\Events\ConfirmationArrived` once the post arrives and `AnvarCO\PayuLatam\Events\ConfirmationSaved` once the confirmation information has been added to the database.

41 changes: 41 additions & 0 deletions migrations/2015_08_25_093443_PayUlatamConfirmationData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class PayUlatamConfirmationData extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('payu_confirmations', function($table)
{
$table->increments('id');
$table->integer('reference_sale')->unsigned();
$table->integer('state_pol');
$table->string('response_code_pol');
$table->string('reference_pol');
$table->string('sign');
$table->string('payment_method');
$table->decimal('value');
$table->decimal('tax');
$table->datetime('transaction_date');
$table->timestamps();
$table->softdeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('payu_confirmations');
}
}
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>
23 changes: 23 additions & 0 deletions src/Confirmation/PayUConfirmation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace AnvarCO\PayuLatam\Confirmation;

use Illuminate\Database\Eloquent\Model;

class PayUConfirmation extends Model{

protected $table = "payu_confirmations";

protected $fillable = [
'reference_sale',
'state_pol',
'response_code_pol',
'reference_pol',
'sign',
'payment_method',
'value',
'tax',
'transaction_date'
];

}
28 changes: 28 additions & 0 deletions src/Events/ConfirmationArrived.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace AnvarCO\PayuLatam\Events;

use Illuminate\Http\Request;


/**
* Class ConfirmationArrived
* @package AnvarCO\PayuLatam\Events
*/
class ConfirmationArrived {

/**
* @var Request
*/
public $confirmationRequest;

/**
* @param Request $confirmationRequest
*/
function __construct(Request $confirmationRequest)
{
$this->confirmationRequest = $confirmationRequest;
}


}
27 changes: 27 additions & 0 deletions src/Events/ConfirmationSaved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace AnvarCO\PayuLatam\Events;


use AnvarCO\PayuLatam\Confirmation\PayUConfirmation;

/**
* Class ConfirmationSaved
* @package AnvarCO\PayuLatam\Events
*/
class ConfirmationSaved {

/**
* @var
*/
public $confirmation;

/**
* @param PayUConfirmation $model
*/
public function __construct(PayUConfirmation $model)
{
$this->confirmation = $model;
}

}
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();
}

}
Loading

0 comments on commit 3755443

Please sign in to comment.