thephpleague / omnipay-paypal

PayPal driver for the Omnipay PHP payment processing library
MIT License
295 stars 174 forks source link

Shipping items #138

Open MaddoxCH opened 8 years ago

MaddoxCH commented 8 years ago

Hello guys, I'm trying to add a shipping amout for my order and I get this error.

    "L_ERRORCODE0" => "10413"
    "L_SHORTMESSAGE0" => "Transaction refused because of an invalid argument. See additional error messages for details."
    "L_LONGMESSAGE0" => "The totals of the cart item amounts do not match order amounts."
    "L_SEVERITYCODE0" => "Error"

There is my item bag: http://puu.sh/qDXWm/23af42b299.png

        "username" => "XXXXXXXXXXXX"
        "password" => "XXXXXXXXXXXX"
        "signature" => "XXXXXXXXXXXX"
        "testMode" => false
        "solutionType" => "Sole"
        "landingPage" => "Billing"
        "brandName" => "YourWine"
        "headerImageUrl" => "http://XXXXXXXXXXXXXXXXXX/img/logo_paypal.png"
        "logoImageUrl" => ""
        "borderColor" => ""
        "cancelUrl" => "http://XXXXXXXXXXXXXXXXXX/payment/cancel"
        "returnUrl" => "http://XXXXXXXXXXXXXXXXXX/payment/sucess"
        "shippingAmount" => "19.00"
        "amount" => "79.00"
        "currency" => "CHF"
delatbabel commented 8 years ago

I think that your error message: "The totals of the cart item amounts do not match order amounts." is correct. PayPal actually checks on their side that the item amounts actually add up to the amount in the purchase() request.

Show your full data including the data that you add to the itemBag and the other parameters that you pass to purchase().

I had a similar issue with PayPal REST but fixed it by including the correct amounts including discounts, transaction fees, shipping fees, etc, in my ItemBag.

MaddoxCH commented 8 years ago

Okay no problem. This is what I have in my params:

$gateway = Omnipay::create('PayPal_Express');
        $gateway->setUsername('XXXXXXXXXXXXXXXXXX');
        $gateway->setPassword('XXXXXXXXXXXXXXXXXX'); 
        $gateway->setSignature('XXXXXXXXXXXXXXXXXX'); 
        $gateway->setTestMode(false); //True for SandBox
        $gateway->setBrandName('YourWine'); 
        $gateway->setHeaderImageUrl(url('img/logo_paypal.png'));

these are my params

            'cancelUrl' => 'http://XXXXXXXXXXXXXXXXXX/payment/cancel',
            'returnUrl' => 'http://XXXXXXXXXXXXXXXXXX/payment/sucess',
            'shippingAmount' =>"19.00",
            'amount' => number_format(Cart::total(), 2) (this it's a value like "60.00")
            'currency' => 'CHF'

and an example of my items:

array:3 [▼
  "name" => "Château La Lagune 1995"
  "quantity" => "1"
  "price" => "60.00"
]

Thanks for you help by the way ^^

MaddoxCH commented 8 years ago

I leave you the full code here !

  if(!Auth::check())
        {
            return redirect('register')->with('errorsLogin','Il faut avoir un compte pour pouvoir commander !');
        }
    {

    }
        //Articles on the cart
        foreach (Cart::content() as $item) {
            dd($items[] = array('name' => $item->name, 'quantity' => $item->qty, 'price' => number_format($item->price,2)));
        }

        //Les différentes URL, le total et la devise.
        if(Cart::total()<= 100)
        {
            $shippingTaxe = "19.00";
        }

        if(Cart::total()> 100 && Cart::total()<= 250)
        {
            $shippingTaxe = "17.00";
        }

        if(Cart::total()> 250 && Cart::total()<= 350)
        {
            $shippingTaxe = "14.00";
        }

        if(Cart::total()> 350 && Cart::total()<= 450)
        {
            $shippingTaxe = "9.00";
        }

        if(Cart::total()> 450)
        {
            $shippingTaxe = "0.0";
        }

        $params = array(
            'cancelUrl' => 'http://XXXXXX.ch/payment/cancel',
            'returnUrl' => 'http://XXXXXX.ch/payment/sucess',
            //'shippingAmount' =>$shippingTaxe,
            'amount' => number_format(Cart::total(), 2),
            'currency' => 'CHF'
        );

        //Put params on the session
        Session::put('params', $params);
        Session::save();

        //On crée notre objet de plateforme de paiement en lui donnant toute les informations nécessaires.
        $gateway = Omnipay::create('PayPal_Express'); 
        $gateway->setUsername('XXXXXXXXXXXXXXXXXX');
        $gateway->setPassword('XXXXXXXXXXXXXXXXXX'); 
        $gateway->setSignature('XXXXXXXXXXXXXXXXXX'); 
        $gateway->setTestMode(false); //True for SandBox
        $gateway->setBrandName('YourWine'); 
        $gateway->setHeaderImageUrl(url('img/logo_paypal.png'));

        //Send the request to paypal
        $response = $gateway->purchase($params)->setItems($items)->send();

        //If it's ok, redirect
        if ($response->isRedirect())
        {
            $response->redirect();
        }
        //Error handle
        else
        {
            return view('payment.error');
        }
delatbabel commented 8 years ago

I think you need to do this:

In your purchase() call:

'amount' => 79.00,
'shipping_amount' => 19.00,

Then in your itemBag the items should add up to the amount - the shipping amount.

See here for the REST API documentation of how these amounts go together. Generally I find that the REST API is much better documented than the old Express API and I would recommend switching to it.

https://developer.paypal.com/docs/api/payments/#payment

Another alternative, which is what I do, is to include the shipping amount as an item in your itemBag and not include it as the shipping amount in the purchase() call.

In your purchase() call:

'amount' => 79.00,

In your itemBag:

array:3 [
    "name" => "Château La Lagune 1995"
    "quantity" => "1"
    "price" => "60.00"
],
array:3 [
    "name" => "Shipping"
    "quantity" => "1"
    "price" => "19.00"
]

... this has the advantage that when the customer opens the item list in the PayPal checkout screen, the shipping will be shown as a line item.

delatbabel commented 8 years ago

Just as a separate point, this is not a support forum for omnipay usage. The correct support forum for omnipay usage help is StackOverflow -- post a question there with the "omnipay" (and in this instance "paypal") tag. This issues system is for reporting bugs with the omnipay code and tracking pull requests on that code.

judgej commented 8 years ago

@Asumii You should change your passwords since you published them on this issue. Even being available for just a few seconds before you edited them out would have been enough for eagle-eyed evil bots to have grabbed them, so assume they are public now.