phppaypalpaypal-sandboxpayout

Got Http response code 403 when accessing https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true


When i try to perform Payout using paypal, i get this error. I tried to avoide sync_mode etc method but didnt help. Please help with this error My function

$payouts = new Payout();
    $senderBatchHeader = new PayoutSenderBatchHeader();
    $senderBatchHeader->setSenderBatchId(uniqid())
        ->setEmailSubject("You have a Payout!");
    $senderItem = new PayoutItem();
    $senderItem->setRecipientType('Email')
        ->setNote('Thanks for your patronage!')
        ->setReceiver('paypalemail@gmail.com')
        ->setSenderItemId("2014031400023")
        ->setAmount(new Currency('{
                    "value":"1.0",
                    "currency":"USD"
                }'));
    $payouts->setSenderBatchHeader($senderBatchHeader)
        ->addItem($senderItem);
    $request = clone $payouts;
    $apiContext = new \PayPal\Rest\ApiContext(
        new \PayPal\Auth\OAuthTokenCredential(
            'client_id',
            'client_secrete_id'
        )
    );
    try {
        $output = $payouts>createSynchronous($apiContext);
    } catch (Exception $ex) {
        return $ex;
    }
    return $output;

Solution

  • Glad that i have found an Answer which worked for me!

    Changed the above code to,

    $payouts = new \PayPal\Api\Payout();
                $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
                $senderBatchHeader->setSenderBatchId(uniqid().microtime(true))
                    ->setEmailSubject("You have a payment");
    
    
                        $senderItem = new \PayPal\Api\PayoutItem();
                        $senderItem->setRecipientType('Email')
                            ->setNote('Thanks you.')
                            ->setReceiver('paypal_email@gmail.com')
                            ->setSenderItemId("item_1" . uniqid().microtime('true'))
                            ->setAmount(new \PayPal\Api\Currency('{
                        "value":"1.0",
                        "currency":"USD"
                    }'));
                        $payouts->setSenderBatchHeader($senderBatchHeader)->addItem($senderItem);
                $request = clone $payouts;
                $apiContext = new \PayPal\Rest\ApiContext(
                    new \PayPal\Auth\OAuthTokenCredential(
                        $paypal->client_id,
                        $paypal->client_secrete
                    )
                );
                try {
                    $output = $payouts->create(null, $apiContext);
                } catch (Exception $ex) {
                Flash::error(trans('payout.payout_error'));
                    return redirect()->back();
                }
                Flash::success(trans('payout.payout_success'));
                return redirect()->back();