Answers for "transfer money from one paypal account to another php"

PHP
0

transfer money from one paypal account to another php

// Get access token from PayPal client Id and secrate key
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_USERPWD, PAYPAL_CLIENT_ID . ":" . PAYPAL_SECRATE_KEY);

            $headers = array();
            $headers[] = "Accept: application/json";
            $headers[] = "Accept-Language: en_US";
            $headers[] = "Content-Type: application/x-www-form-urlencoded";
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            $results = curl_exec($ch);
            $getresult = json_decode($results);


            // PayPal Payout API for Send Payment from PayPal to PayPal account
            curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            $array = array('sender_batch_header' => array(
                    "sender_batch_id" => time(),
                    "email_subject" => "You have a payout!",
                    "email_message" => "You have received a payout."
                ),
                'items' => array(array(
                        "recipient_type" => "EMAIL",
                        "amount" => array(
                            "value" => '100',
                            "currency" => "USD"
                        ),
                        "note" => "Thanks for the payout!",
                        "sender_item_id" => time(),
                        "receiver" => '[email protected]'
                    ))
            );
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
            curl_setopt($ch, CURLOPT_POST, 1);

            $headers = array();
            $headers[] = "Content-Type: application/json";
            $headers[] = "Authorization: Bearer $getresult->access_token";
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            $payoutResult = curl_exec($ch);
            //print_r($result);
            $getPayoutResult = json_decode($payoutResult);
            if (curl_errno($ch)) {
                echo 'Error:' . curl_error($ch);
            }
            curl_close($ch);
            print_r($getPayoutResult);
Posted by: Guest on July-21-2021

Code answers related to "transfer money from one paypal account to another php"

Browse Popular Code Answers by Language