weixin_39563722 2020-11-30 11:55
浏览 0

the response tells me that I miss total amount

Hi , I'm working onn laravel package , but when I process my payment . I get this response issue

my code as bellow


    // ### 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
    $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->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->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")
        ->setSubtotal("17.5");

    //Payment Amount
    $amount = Paypalpayment::amount();
    $amount->setCurrency("USD")
        ->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);

Response issue [11-12-2014 05:49:11] PayPal\Core\PPHttpConnection: FINE: Response : {"name":"VALIDATION_ERROR","details":[{"field":"transactions","issue":"Item amount must add up to specified amount subtotal (or total if amount details not specified)"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"d993059e951ad"}

该提问来源于开源项目:paypal/PayPal-PHP-SDK

  • 写回答

0条回答 默认 最新

    报告相同问题?