Comments (2)
Yes, it works on laravel 5.2 also, i have tested it; ensure the logging is set to false, or ensure the log file is reachable. This item can be closed it works like charm...
<?php
namespace App\Http\Controllers\Ecommerce;
use Illuminate\Http\Request;
use Paypalpayment;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PaymentController extends Controller
{
/**
* object to authenticate the call.
* @param object $_apiContext
*/
private $_apiContext;
/**
* Set the ClientId and the ClientSecret.
* @param
*string $_ClientId
*string $_ClientSecret
*/
private $_ClientId = "";
private $_ClientSecret="";
/*
* These construct set the SDK configuration dynamiclly,
* If you want to pick your configuration from the sdk_config.ini file
* make sure to update you configuration there then grape the credentials using this code :
* $this->_cred= Paypalpayment::OAuthTokenCredential();
*/
public function __construct()
{
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call. You can also send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
$this->_ClientId = config('paypal_payment.Account.ClientId');
$this->_ClientSecret = config('paypal_payment.Account.ClientSecret');
$this->_apiContext = Paypalpayment::ApiContext($this->_ClientId, $this->_ClientSecret);
// Uncomment this step if you want to use per request
// dynamic configuration instead of using sdk_config.ini
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => false,
'log.FileName' => __DIR__.'/../../PayPal.log',
'log.LogLevel' => 'FINE'
));
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
echo "<pre>";
$payments = Paypalpayment::getAll(array('count' => 1, 'start_index' => 0), $this->_apiContext);
dd($payments);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return View::make('payment.order');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// ### Address
// Base Address object used as shipping or billing
// address in a payment. [Optional]
$addr= Paypalpayment::address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostalCode("14305");
$addr->setCountryCode("US");
$addr->setPhone("716-298-1822");
// ### CreditCard
$card = Paypalpayment::creditCard();
$card->setType("visa")
->setNumber("4758411877817150")
->setExpireMonth("05")
->setExpireYear("2019")
->setCvv2("456")
->setFirstName("Joe")
->setLastName("Shopper");
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// Use a Payer ID (A unique identifier of the payer generated
// and provided by the facilitator. This is required when
// creating or using a tokenized funding instrument)
// and the `CreditCardDetails`
$fi = Paypalpayment::fundingInstrument();
$fi->setCreditCard($card);
// ### Payer
// A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method
// as 'credit_card'
$payer = Paypalpayment::payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
$item1 = Paypalpayment::item();
$item1->setName('Ground Coffee 40 oz')
->setDescription('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setTax(0.3)
->setPrice(7.50);
$item2 = Paypalpayment::item();
$item2->setName('Granola bars')
->setDescription('Granola Bars with Peanuts')
->setCurrency('USD')
->setQuantity(5)
->setTax(0.2)
->setPrice(2);
$itemList = Paypalpayment::itemList();
$itemList->setItems(array($item1,$item2));
$details = Paypalpayment::details();
$details->setShipping("1.2")
->setTax("1.3")
//total of items prices
->setSubtotal("17.5");
//Payment Amount
$amount = Paypalpayment::amount();
$amount->setCurrency("USD")
// the total is $17.8 = (16 + 0.6) * 1 ( of quantity) + 1.2 ( of Shipping).
->setTotal("20")
->setDetails($details);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = Paypalpayment::transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
// ### Payment
// A Payment Resource; create one using
// the above types and intent as 'sale'
$payment = Paypalpayment::payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
try {
// ### Create Payment
// Create a payment by posting to the APIService
// using a valid ApiContext
// The return object contains the status;
$payment->create($this->_apiContext);
} catch (\PPConnectionException $ex) {
return "Exception: " . $ex->getMessage() . PHP_EOL;
exit(1);
}
dd($payment);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($payment_id)
{
$payment = Paypalpayment::getById($payment_id,$this->_apiContext);
dd($payment);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
from laravel-paypalpayment.
What do I need to add in my code for the auto return from paypal in Laravel 5.2?
`
`
from laravel-paypalpayment.
Related Issues (20)
- NOSHIPPING attr
- Cards ?
- Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment. HOT 3
- Invalid argument supplied for foreach()
- Error in laravel 5.5 PaypalPayment does not exist. HOT 1
- Please update paypal SDK to latest version HOT 3
- See Payment with PayPal Function HOT 1
- credit and debit?
- Class paypalpayment does not exist
- error_log(../PayPal.log): failed to open stream: Permission denied HOT 1
- _convertToArray() error HOT 3
- Can se set Currency other than USD HOT 1
- Discount Issues, very big problem
- Dynamic methods should not be called staticaly
- Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment
- paypal/rest-api-sdk-php version HOT 6
- laravel 6 version it can not be install
- How you update? HOT 1
- How to override configuration in controller?
- Need package update HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-paypalpayment.