srmklive / laravel-paypal

Laravel plugin for processing payments through PayPal.
https://laravel-paypal-demo.srmk.info/
MIT License
1.05k stars 316 forks source link

No demo or docs on how to use version 3.0, read me is confusing once I'm on the usage part. #407

Closed gr34tnull closed 2 years ago

gr34tnull commented 3 years ago

No demo or docs on how to use version 3.0, read me is confusing once I'm on the usage part.

joelmatisa commented 3 years ago

Salut les gars, je pense que cette question de concerne pas trop le package mais besoin d'aide:

j'ai toujours cette erreur dont j'ai comprend pas d'où ca vient:

    "message" => "{} {"name":"NOT_AUTHORIZED","details":[{"issue":"PERMISSION_DENIED","description":"You do not have permission to access or perform operations on this resource."}],"message":"Authorization failed due to insufficient permissions.","debug_id":"79010a47e43c0","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-PERMISSION_DENIED","rel":"information_link"}]} ", 

je suis dans sandbax, où toute les identifiant fonctionne bien et quand j'appelle la methode $this->provider->capturePaymentOrder($enrollment->payment_transaction)

public function paymentSuccess() { // Check if User has Enrollment $enrollment = Enrollment::where('user_id', auth()->id())->firstOrCreate(['user_id' => auth()->id()]);

    // Init PayPal 
    $provider = \PayPal::setProvider();
    $provider->setApiCredentials(config('paypal'));
    $token = $provider->getAccessToken();
    $provider->setAccessToken($token);

    // Get PaymentOrder using our transaction ID
    $order = $provider->capturePaymentOrder($enrollment->payment_transaction);

    // Save that payment was made (example)
    $enrollment->payment_at = Carbon::now();
    $enrollment->save();

    // Return Redirect
    return redirect()->route('my.route.to.dashboard')->withFlashSuccess('Payment Confirmed!');
}

@robertholf @srmklive

robertholf commented 3 years ago

Salut les gars, je pense que cette question de concerne pas trop le package mais besoin d'aide: j'ai toujours cette erreur dont j'ai comprend pas d'où ca vient:

@joelmatisa did you configure the credentials correctly? Also how old is the App? They updated it a while back so you may just create a new app and use those creds if the other one is old..

joelmatisa commented 3 years ago

Thanks for your answer but the app is new, Laravel, and for credentials it’s use just essentially client_id and secret_key

I create good the order with that // Prepare Order $order = $provider->createOrder([ 'intent'=> 'CAPTURE', 'purchase_units'=> [[ 'reference_id' => 'transaction_test_number'. $enrollment->id, 'amount'=> [ 'currency_code'=> 'USD', 'value'=> '20.00' ] ]], 'application_context' => [ 'cancel_url' => 'http://myproject.test/dashboard/payment/cancel', 'return_url' => 'http://myproject.test/dashboard/payment/success' ] ]); And I’m right redirect to “checkout now” and when I login with sandbox account after that line $this->provider->capturePaymentOrder($enrollment->payment_transaction) caused the the errors Not-Authorized

robertholf commented 3 years ago

recommend opening a ticket with PayPal, i dont think its a code thing.

joelmatisa commented 3 years ago

@robertholf there is a particular configuration when we create a sandbox account, I ask just by way 😁

adgower commented 3 years ago

Hello everyone, I hope this is useful:

NOTE: The "Enrollment" model is application specific to me, you can ignore the enrollment thing but i needed to store the token somewhere and determine if they paid or not.

    public function paymentProcess()
    {
        // Check if User has Enrollment
        $enrollment = Enrollment::where('user_id', auth()->id())->firstOrCreate(['user_id' => auth()->id()]);

        // Init PayPal
        $provider = \PayPal::setProvider();
        $provider->setApiCredentials(config('paypal')); // Pull values from Config
        $token = $provider->getAccessToken();
        $provider->setAccessToken($token);

        // Prepare Order
        $order = $provider->createOrder([
            'intent'=> 'CAPTURE',
            'purchase_units'=> [[
                'reference_id' => 'transaction_test_number'. $enrollment->id,
                'amount'=> [
                  'currency_code'=> 'USD',
                  'value'=> '20.00'
                ]
            ]],
            'application_context' => [
                 'cancel_url' => 'http://myproject.test/dashboard/payment/cancel',
                 'return_url' => 'http://myproject.test/dashboard/payment/success'
            ]
        ]);

        // Store Token so we can retrieve after PayPal sends them back to us
        $enrollment->payment_transaction = $order['id'];
        $enrollment->save();

        // Send user to PayPal to confirm payment
        return redirect($order['links'][1]['href'])->send();

@srmklive what is missing from the documentation is the application_context which i found by reviewing: https://github.com/paypal/Checkout-PHP-SDK#code

            'application_context' => [
                 'cancel_url' => 'http://myproject.test/dashboard/payment/cancel',
                 'return_url' => 'http://myproject.test/dashboard/payment/success'
            ]

Then on the Payment Success (the return URL)

    public function paymentSuccess() {
        // Check if User has Enrollment
        $enrollment = Enrollment::where('user_id', auth()->id())->firstOrCreate(['user_id' => auth()->id()]);

        // Init PayPal 
        $provider = \PayPal::setProvider();
        $provider->setApiCredentials(config('paypal'));
        $token = $provider->getAccessToken();
        $provider->setAccessToken($token);

        // Get PaymentOrder using our transaction ID
        $order = $provider->capturePaymentOrder($enrollment->payment_transaction);

        // Save that payment was made (example)
        $enrollment->payment_at = Carbon::now();
        $enrollment->save();

        // Return Redirect
        return redirect()->route('my.route.to.dashboard')->withFlashSuccess('Payment Confirmed!');
    }

What would be the reason to use this package vs https://github.com/paypal/Checkout-PHP-SDK

I apologize for my ignorance, but when using the checkout php sdk you have to do the exact same steps?

joelmatisa commented 3 years ago

Hi @adgower just a precision we can init // Init PayPal $provider = \PayPal::setProvider(); $provider->setApiCredentials(config('paypal')); $token = $provider->getAccessToken(); $provider->setAccessToken($token); in constructor? for to reference it's as $this->provider ! I look for my error

adgower commented 3 years ago

Hi @adgower just a precision we can init // Init PayPal $provider = \PayPal::setProvider(); $provider->setApiCredentials(config('paypal')); $token = $provider->getAccessToken(); $provider->setAccessToken($token); in constructor? for to reference it's as $this->provider ! I look for my error

Hey Joel,

I don't understand what you are saying, but using paypal sdk you can init the client like this:

$paypal = new PayPalHttpClient(new SandboxEnvironment(config('paypal.sandbox.client_id'), config('paypal.sandbox.client_secret')));
verticalfx commented 3 years ago

Anyone figured out how to issue full refunds using this package?

jahir07 commented 3 years ago

is there any workable github repo for version 3?

artytech1 commented 2 years ago

i done stripe api for my new website without any problem, but im really stuck on this package for hours. im gettings this error all the time: "Request is not well-formed, syntactically incorrect, or violates schema."

artytech1 commented 2 years ago

ohh yess i got things package working after couple of hours :D

jahir07 commented 2 years ago

ohh yess i got things package working after couple of hours :D

can you please share

artytech1 commented 2 years ago

@jahir07 Hi, i posted too long code before with my own functions inside . so just try. install package v3. in your controller define this: use Srmklive\PayPal\Services\PayPal as PayPalClient;

define routes: Route::post('/paypal/order/', [CheckoutController::class, 'paypal_order'])->name('paypal.order'); Route::get('/payment-success/', [CheckoutController::class, 'payment_success']); (for me was enough with two routes only)

make function for paypal order. `public function paypal_order(Request $request)

{
    $provider = new PayPalClient([]);
    $token = $provider->getAccessToken();
    $provider->setAccessToken($token);
    $courierPrice = $request->courier;
    if(Session::has('coupon')) {
        $total_amount = number_format(Session::get('coupon')['total_amount'] + $courierPrice,2);
        $totalAmount = number_format(Session::get('coupon')['total_amount'],2);
    } else {
        $total_amount = number_format(Cart::total() + $courierPrice,2);
        $totalAmount = number_format(Cart::total(),2);
    }
    $order = $provider->createOrder([
        "intent"=> "CAPTURE",
        "purchase_units" => [[
            'reference_id' => Carbon::now(),
            'amount' => [
                'currency_code'=> 'GBP',
                'value'=> number_format($total_amount,2)
            ]
        ]],
        'application_context' => [
            'cancel_url' => 'http://127.0.0.1:8000/checkout/',
            'return_url' => 'http://127.0.0.1:8000/payment-success/'
        ]
    ]);
   return redirect($order['links'][1]['href'])->send();
}`

above is some my own function don't look at it pass your own price from whatever is comes from.

from payment_success link follows this function:

` public function payment_success(Request $request) { $provider = new PayPalClient; $provider->setApiCredentials(config('paypal')); $provider->getAccessToken(); $response = $provider->capturePaymentOrder($request['token']);

    if (isset($response['status']) && $response['status'] == 'COMPLETED') {
                   //execute your own code, insert order in database etc.
                    i use bumbummen99/shoppingcart easy to get all products. and some data like address i store in session.
    }`
 }

please let me know if its working for you. sorry for my english.

jahir07 commented 2 years ago

@artytech1 thanks a lot

artytech1 commented 2 years ago

@jahir07 no problem m8, i hope everything is working for you now :))