anouarabdsslm / laravel-paypalpayment

Laravel paypal payment package , help you process credit card payment using paypal api
Apache License 2.0
337 stars 198 forks source link

Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment. #146

Open taporag opened 6 years ago

taporag commented 6 years ago

Please help me to solve this problem. Am i missing something? The bellow codes working something but now it's not working............... What type of issue it is?

Error Expection PayPal \ Exception \ PayPalConnectionException (500) Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment. ![paypal500](https://user-images.githubusercontent.com/32647267/39098506-ad8f2986-468d-11e8-8a8e-0832b403a9c4.png)

Here is the codes ` public function paywithCreditCard() { // ### Address // Base Address object used as shipping or billing // address in a payment. [Optional] $shippingAddress = Paypalpayment::shippingAddress(); $shippingAddress->setLine1("3909 Witmer Road") ->setLine2("Niagara Falls") ->setCity("Niagara Falls") ->setState("NY") ->setPostalCode("14305") ->setCountryCode("US") ->setPhone("716-298-1822") ->setRecipientName("Jhone");

    // ### 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([$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([$item1,$item2])
        ->setShippingAddress($shippingAddress);

    $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([$transaction]);

    try {
        // ### Create Payment
        // Create a payment by posting to the APIService
        // using a valid ApiContext
        // The return object contains the status;
        $payment->create(Paypalpayment::apiContext());
    } catch (\PPConnectionException $ex) {
        return response()->json(["error" => $ex->getMessage()], 400);
    }

    return response()->json([$payment->toArray()], 200);
}

`

Akashverma11 commented 6 years ago

I am also getting this problem. how can i catch this exception. exception handler is not able to catch the exception. please help me.

taporag commented 6 years ago

To catch any type of exceptions you can just use Exception instead of \PPConnectionException

Akashverma11 commented 6 years ago

thanks its working.......