Skip to content

Commit

Permalink
Cambiando permisos en linux. Se agrego el sdk de paypal y se realizo …
Browse files Browse the repository at this point in the history
…el cobro del producto del carrito de compra. Creando el modelo PayPal en el cual se genera el cobro de los productos y retornando la informacion en el controlador PaymentsController
  • Loading branch information
zaratedev committed Aug 6, 2017
1 parent 87330b5 commit 747c706
Show file tree
Hide file tree
Showing 139 changed files with 1,080 additions and 129 deletions.
Empty file modified .env.example
100644 → 100755
Empty file.
Empty file modified .gitattributes
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified app/Console/Kernel.php
100644 → 100755
Empty file.
Empty file modified app/Exceptions/Handler.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/ForgotPasswordController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/LoginController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/RegisterController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/ResetPasswordController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Controller.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/HomeController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/InShoppingCartsController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/MainController.php
100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions app/Http/Controllers/PaymentsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\PayPal;
use App\ShoppingCart;

class PaymentsController extends Controller
{
public function store(Request $request)
{
$shopping_cart_id = \Session::get('shopping_cart_id');

$shopping_cart = ShoppingCart::findOrCreateBySessionID($shopping_cart_id );

$paypal = new PayPal($shopping_cart);

dd($paypal->execute($request->paymentId, $request->PayerID));

}
}
Empty file modified app/Http/Controllers/ProductoController.php
100644 → 100755
Empty file.
10 changes: 7 additions & 3 deletions app/Http/Controllers/ShoppingCartsController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use App\ShoppingCart;
use App\PayPal;
class ShoppingCartsController extends Controller
{
public function index()
Expand All @@ -12,10 +13,13 @@ public function index()

$shopping_cart = ShoppingCart::findOrCreateBySessionID($shopping_cart_id );

$productos = $shopping_cart->productos()->get();
$paypal = new PayPal($shopping_cart);
$payment = $paypal->generate();
return redirect($payment->getApprovalLink());
//$productos = $shopping_cart->productos()->get();

$total = $shopping_cart->total();
//$total = $shopping_cart->total();

return view('shopping_carts.index',compact('productos','total'));
//return view('shopping_carts.index',compact('productos','total'));
}
}
Empty file modified app/Http/Kernel.php
100644 → 100755
Empty file.
Empty file modified app/Http/Middleware/EncryptCookies.php
100644 → 100755
Empty file.
Empty file modified app/Http/Middleware/RedirectIfAuthenticated.php
100644 → 100755
Empty file.
Empty file modified app/Http/Middleware/TrimStrings.php
100644 → 100755
Empty file.
Empty file modified app/Http/Middleware/VerifyCsrfToken.php
100644 → 100755
Empty file.
Empty file modified app/InShoppingCart.php
100644 → 100755
Empty file.
89 changes: 89 additions & 0 deletions app/PayPal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
namespace App;

/**
*
*/
class PayPal
{
private $_apiContext;
private $shopping_cart;
private $_ClienteId = 'AVcxxcMEiJnLeivSW8LKdM9y8K09kR6OwJPP2kn-GZL0GDASiW2N3LXDnQc6ftboInfQydcZeLkLF9QL';
private $_ClienteSecret = 'EL6tZsslqnpp9Q-MtIwp55ixIRrRKVnMV7BoUpEPJA0bqOf6lMouZJDJ8c-JGBg4tA2dfuYeR8IBVhIm';

public function __construct($shopping_cart)
{
$this->_apiContext = \Paypalpayment::apiContext($this->_ClienteId, $this->_ClienteSecret);
$config = config("paypal_payment");
$flatConfig = array_dot($config);
$this->_apiContext->setConfig($flatConfig);
$this->shopping_cart = $shopping_cart;
}

public function generate()
{
$payment = \Paypalpayment::payment()->setIntent('sale')
->setPayer($this->payer())
->setTransactions([$this->transaction()])
->setRedirectUrls($this->redirectURLs());

try {
$payment->create($this->_apiContext);
} catch (\Exception $e) {
dd($e);
exit(1);
}
return $payment;

}

public function payer()
{
//return payment Information
return \Paypalpayment::payer()->setPaymentMethod('paypal');
}
public function redirectURLs()
{
$baseURL = url('/');
return \Paypalpayment::redirectUrls()
->setReturnUrl("$baseURL/payments/store")
->setCancelUrl("$baseURL/carrito");


}
public function transaction()
{
return \Paypalpayment::transaction()->setAmount($this->amount())
->setItemList($this->items())
->setDescription("Tu compra en programacion jje")
->setInvoiceNumber(uniqid());
}
public function items()
{
$items = [];
$products = $this->shopping_cart->productos()->get();
foreach ($products as $product) {
array_push($items, $product->paypalItem());
}
return \Paypalpayment::itemList()->setItems($items);
}
public function amount()
{
return \Paypalpayment::amount()->setCurrency('USD')
->setTotal($this->shopping_cart->totalUSD());
}

public function execute($paymentId, $payerId)
{
$payment = \Paypalpayment::getById($paymentId, $this->_apiContext);

$execution = \Paypalpayment::PaymentExecution()->setPayerId($payerId);

return $payment->execute($execution, $this->_apiContext);
}

}



?>
9 changes: 9 additions & 0 deletions app/Producto.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ class Producto extends Model
protected $fillable = [
'user_id','title', 'description', 'pricing',
];

public function paypalItem()
{
return \Paypalpayment::item()->setName($this->title)
->setDescription($this->description)
->setCurrency('USD')
->setQuantity(1)
->setPrice($this->pricing / 100);
}
}
Empty file modified app/Providers/AppServiceProvider.php
100644 → 100755
Empty file.
Empty file modified app/Providers/AuthServiceProvider.php
100644 → 100755
Empty file.
Empty file modified app/Providers/BroadcastServiceProvider.php
100644 → 100755
Empty file.
Empty file modified app/Providers/EventServiceProvider.php
100644 → 100755
Empty file.
Empty file modified app/Providers/RouteServiceProvider.php
100644 → 100755
Empty file.
Empty file modified app/Providers/ShoppingCartProvider.php
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions app/ShoppingCart.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function total()
{
return $this->productos()->sum('pricing');
}
public function totalUSD()
{
return $this->productos()->sum('pricing') / 100;
}
public static function findOrCreateBySessionID($shopping_cart_id)
{
if ($shopping_cart_id) {
Expand Down
Empty file modified app/User.php
100644 → 100755
Empty file.
Empty file modified artisan
100644 → 100755
Empty file.
Empty file modified bootstrap/app.php
100644 → 100755
Empty file.
Empty file modified bootstrap/autoload.php
100644 → 100755
Empty file.
Empty file modified bootstrap/cache/.gitignore
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.4.0"
"laravelcollective/html": "^5.4.0",
"anouar/paypalpayment": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
Loading

0 comments on commit 747c706

Please sign in to comment.