anouarabdsslm/laravel-paypalpayment

Problem code 415 error

leifermendez opened this issue · 1 comments

'Got Http response code 415 when accessing https://api.paypal.com/v1/oauth2/token.'

` public function create($amount=null,$id_order=null)
{

 //Example $amount = 100;
    $pay_amount = floatval($amount);

    if(is_null($pay_amount)){
        $response = array(
            'status' => 'fail',
            'msj' => 'Monto no existe',
            'code' => 5
        );
        return response()->json($response);
    }


    $currency= 'USD';

    $payer = Paypalpayment::payer();
    $payer->setPaymentMethod("paypal");

    $pay_amount = floatval($pay_amount);
    $amount = Paypalpayment::amount();
    $amount->setCurrency($currency)
        ->setTotal($pay_amount);


    $transaction = Paypalpayment::transaction();
    $transaction->setAmount($amount)
        ->setDescription("Payment description")
        ->setInvoiceNumber(uniqid());


    $baseUrl = config('app.url');
    $redirectUrls = Paypalpayment::redirectUrls();
    $redirectUrls->setReturnUrl("{$baseUrl}/payres?status=success&id_order=".$id_order->id)
        ->setCancelUrl("URL FAIL");


    $payment = Paypalpayment::payment();
    $payment->setIntent("sale")
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions(array($transaction));


    try {
        $payment->create($this->_apiContext);
    } catch (\Exception $ex) {
        \Log::error($ex);
    }


    $approvalUrl = $payment->getApprovalLink();

    return $approvalUrl;
}`

@leifermendez can you follow the video here https://www.youtube.com/watch?v=F67YuGKm220 and if that did not help to resolve your issue just hit me back here and I will investigate that.