GithubHelp home page GithubHelp logo

Comments (16)

anouarabdsslm avatar anouarabdsslm commented on August 25, 2024

1- Check the installation :

Install this package through Composer. To your composer.json file, add:

"require-dev": {
    "anouar/paypalpayment": "dev-master"
}

Next, run composer install to download it.

2- verify the package within tou project
vendor
|_ anouar
|_paypalpayment

3- Add the service provider to app/config/app.php, within the providers array.

'providers' => array(
    // ...

    'Anouar\Paypalpayment\PaypalpaymentServiceProvider',
)

4- add the alias to app/config/app.php, within the aliases array.

'aliases' => array(
    // ...

    'Paypalpayment'   => 'Anouar\Paypalpayment\Facades\PaypalPayment',
)

5 go to you controllers and create this controller

<?php 

class PaypalPaymentController extends BaseController {
    /**
     * object to authenticate the call.
     * @param object $_apiContext
     */
    private $_apiContext;

    /**
     * Set the ClientId and the ClientSecret.
     * @param 
     *string $_ClientId
     *string $_ClientSecret
     */
    private $_ClientId='AVJx0RArQzkCCsWC0evZi1SsoO4gxjDkkULQBdmPNBZT4fc14AROUq-etMEY';
    private $_ClientSecret='EH5F0BAxqonVnP8M4a0c6ezUHq-UT-CWfGciPNQOdUlTpWPkNyuS6eDN-tpA';

    /*
     *   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->_apiContext = Paypalpayment:: ApiContext(
                Paypalpayment::OAuthTokenCredential(
                    $this->_ClientId,
                    $this->_ClientSecret
                )
        );

        // dynamic configuration instead of using sdk_config.ini

        $this->_apiContext->setConfig(array(
            'mode' => 'sandbox',
            'http.ConnectionTimeOut' => 30,
            'log.LogEnabled' => true,
            'log.FileName' => __DIR__.'/../PayPal.log',
            'log.LogLevel' => 'FINE'
        ));

    }

    /*
     * Create payment using credit card
     * url:payment/create
    */
    public function create(){

        // ### 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->setPostal_code("14305");
        $addr->setCountry_code("US");
        $addr->setPhone("716-298-1822");

        // ### CreditCard
        // A resource representing a credit card that can be
        // used to fund a payment.
        $card = Paypalpayment::CreditCard();
        $card->setType("visa");
        $card->setNumber("4417119669820331");
        $card->setExpire_month("11");
        $card->setExpire_year("2019");
        $card->setCvv2("012");
        $card->setFirst_name("Anouar");
        $card->setLast_name("Abdessalam");
        $card->setBilling_address($addr);

        // ### 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->setCredit_card($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->setPayment_method("credit_card");
        $payer->setFunding_instruments(array($fi));

        // ### Amount
        // Let's you specify a payment amount.
        $amount = Paypalpayment:: Amount();
        $amount->setCurrency("USD");
        $amount->setTotal("1.00");

        // ### 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);
        $transaction->setDescription("This is the payment description.");

        // ### Payment
        // A Payment Resource; create one using
        // the above types and intent as 'sale'
        $payment = Paypalpayment:: Payment();
        $payment->setIntent("sale");
        $payment->setPayer($payer);
        $payment->setTransactions(array($transaction));

        // ### Create Payment
        // Create a payment by posting to the APIService
        // using a valid ApiContext
        // The return object contains the status;
        try {
            $payment->create($this->_apiContext);
        } catch (\PPConnectionException $ex) {
            return "Exception: " . $ex->getMessage() . PHP_EOL;
            var_dump($ex->getData());
            exit(1);
        }

        $response=$payment->toArray();

        echo"<pre>";
        print_r($response);

        //var_dump($payment->getId());

        //print_r($payment->toArray());//$payment->toJson();
    }  

    /*
        Use this call to get a list of payments. 
        url:payment/
    */
    public function index(){

        echo "<pre>";

        $payments = Paypalpayment::all(array('count' => 1, 'start_index' => 0),$this->_apiContext);

         print_r($payments);
    }
}

6- go to route add add this guy

Route::resource('payment', 'PaypalPaymentController');

7-go to http://localhost:8000/payment

if everythin set correctly should get a response .

from laravel-paypalpayment.

justgage avatar justgage commented on August 25, 2024

Cool! seems to have worked! the only thing I had to do was switch out composer update for composer update anouar/paypalpaymen thanks so much for the reply!

from laravel-paypalpayment.

anouarabdsslm avatar anouarabdsslm commented on August 25, 2024

you're welcome feel free to ask , and I'll replay as soon as possible .

from laravel-paypalpayment.

imdketav avatar imdketav commented on August 25, 2024

@xroot I have followed all steps as you mention but when I run script it will through an error like this.
FatalErrorException in PaypalPaymentController.php line 41:
Class 'Paypalpayment' not found
screenshot from 2015-10-08 18 33 58

from laravel-paypalpayment.

chilion avatar chilion commented on August 25, 2024

Seems like you didn't add a USE in the top of your code? Can you show your code?

from laravel-paypalpayment.

imdketav avatar imdketav commented on August 25, 2024

@chilion This is my code where my_app is my application name

_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->_apiContext = Paypalpayment:: ApiContext( Paypalpayment::OAuthTokenCredential( $this->_ClientId, $this->_ClientSecret ) ); // dynamic configuration instead of using sdk_config.ini $this->_apiContext->setConfig(array( 'mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => __DIR__.'/../PayPal.log', 'log.LogLevel' => 'FINE' )); } /* * Create payment using credit card * url:payment/create */ public function create(){ // ### 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->setPostal_code("14305"); $addr->setCountry_code("US"); $addr->setPhone("716-298-1822"); // ### CreditCard // A resource representing a credit card that can be // used to fund a payment. $card = Paypalpayment::CreditCard(); $card->setType("visa"); $card->setNumber("4417119669899999"); $card->setExpire_month("01"); $card->setExpire_year("2099"); $card->setCvv2("012"); $card->setFirst_name("Anouar"); $card->setLast_name("Abdessalam"); $card->setBilling_address($addr); // ### 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->setCredit_card($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->setPayment_method("credit_card"); $payer->setFunding_instruments(array($fi)); // ### Amount // Let's you specify a payment amount. $amount = Paypalpayment:: Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); // ### 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); $transaction->setDescription("This is the payment description."); // ### Payment // A Payment Resource; create one using // the above types and intent as 'sale' $payment = Paypalpayment:: Payment(); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); // ### Create Payment // Create a payment by posting to the APIService // using a valid ApiContext // The return object contains the status; try { $payment->create($this->_apiContext); } catch (\PPConnectionException $ex) { return "Exception: " . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } $response=$payment->toArray(); echo"
";
    print_r($response);

    //var_dump($payment->getId());

    //print_r($payment->toArray());//$payment->toJson();
}  

/*
    Use this call to get a list of payments. 
    url:payment/
*/
public function index(){

    echo "
";

    $payments = Paypalpayment::all(array('count' => 1, 'start_index' => 0),$this->_apiContext);

     print_r($payments);
}
```

}

from laravel-paypalpayment.

chilion avatar chilion commented on August 25, 2024

Ah allright, seems good. config/app.php, added facades and serviceprovider

from laravel-paypalpayment.

imdketav avatar imdketav commented on August 25, 2024

@chilion in my config/app.php file there is not a service provider but providers is there and i already add this line to providers array
Anouar\Paypalpayment\PaypalpaymentServiceProvider::class,

and in Aliases array
'Paypalpayment' => Anouar\Paypalpayment\Facades\PaypalPayment::class,

But there is not a single work like facades..

from laravel-paypalpayment.

anouarabdsslm avatar anouarabdsslm commented on August 25, 2024

@imdketav : try composer dumpautoload if it doest work , please watch the video https://www.youtube.com/watch?v=q5Xb5r4MUB8 you may missed something

from laravel-paypalpayment.

imdketav avatar imdketav commented on August 25, 2024

@xroot : Video given you that helps me a lot. But I'm still getting one error like this Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.

How can I fix this error?
screenshot from 2015-10-09 15 24 49

from laravel-paypalpayment.

anouarabdsslm avatar anouarabdsslm commented on August 25, 2024

@imdketav share with me your code , also make sure your paypal API keys are correct , for testing use sandbox api keys

from laravel-paypalpayment.

imdketav avatar imdketav commented on August 25, 2024

@xroot Following is my code
Code of PaypalPaymentController.php
<?php

namespace my_app\Http\Controllers;

use Illuminate\Http\Request;
use my_app\Http\Requests;
use my_app\Http\Controllers\Controller;
use Paypalpayment;

class PaypalPaymentController extends Controller {
 /**
     * object to authenticate the call.
     * @param object $_apiContext
     */
    private $_apiContext;

    /*
     *   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->_apiContext = Paypalpayment::ApiContext(config('paypal_payment.Account.ClientId'), config('paypal_payment.Account.ClientSecret'));


    }

     /*
        Use this call to get a list of payments. 
        url:payment/
    */
    public function index()
    {
        echo "<pre>";

        $payments = Paypalpayment::getAll(array('count' => 1, 'start_index' => 0), $this->_apiContext);

        dd($payments);
    }
 /*
    * Display form to process payment using credit card
    */
    public function create()
    {
        echo "Hello";die;
        return View::make('payment.order');
    }

    /*
    * Process payment using credit card
    */
    public function store()
    {
        // ### 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);
    } 

        /*
        Use this call to get details about payments that have not completed, 
        such as payments that are created and approved, or if a payment has failed.
        url:payment/PAY-3B7201824D767003LKHZSVOA
    */

    public function show($payment_id)
    {
       $payment = Paypalpayment::getById($payment_id,$this->_apiContext);

       dd($payment);
    }

}

Routers.php

Route::post('payment', 'PaypalPaymentController@create');

config/app.php

'providers' => [
//My code
Anouar\Paypalpayment\PaypalpaymentServiceProvider::class,
//My code
],
'aliases' => [
//My Code
'Paypalpayment' => Anouar\Paypalpayment\Facades\PaypalPayment::class,
//My Code
],

Client ID and Client Secret Both are correct that i know.
This is a code which i did and i am getting following error while i'm trying to run it.
with POST Method
selection_005

with GET Method
selection_006

from laravel-paypalpayment.

anouarabdsslm avatar anouarabdsslm commented on August 25, 2024

@imdketav : I have updated your code , check it now , from the error I may guess you're not using the correct API keys.

from laravel-paypalpayment.

imdketav avatar imdketav commented on August 25, 2024

@xroot : I'm still getting same error..
when I use Client ID and Client Secret in Core PHP Paypal Integration then it works perfectly. Only in Laravel I'm facing problem.

from laravel-paypalpayment.

anouarabdsslm avatar anouarabdsslm commented on August 25, 2024

@imdketav please watch this video https://www.youtube.com/watch?v=q5Xb5r4MUB8&feature=youtu.be

from laravel-paypalpayment.

karthikjs avatar karthikjs commented on August 25, 2024

@anouarabdsslm
am getting

PaymentHistory {#171
-_propMap: []
}
what response am getting. how proceed next step.....

how to give a payment details via api as well as website. pls help


from laravel-paypalpayment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.