Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreatePayoutSample.php #20

Open
sampler9 opened this issue Nov 18, 2022 · 0 comments
Open

CreatePayoutSample.php #20

sampler9 opened this issue Nov 18, 2022 · 0 comments

Comments

@sampler9
Copy link

I downloaded the sdk and unzipped it in my directory paypalpayouts. The directory name that unzipped is /public_html/paypalpayouts/Payouts-PHP-SDK-master/CreatePayoutSample.php. I ran the install composer then ran CLIENT_ID=AcRivaHqeubISibpYNCVQIZpzHoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CLIENT_SECRET=EH9NYd5DudNZ2klWcNkFWclqcsJdReExxxxxxxxxxxxxxxxxxxxxxxxxxx composer unit (which errored btw with (Script phpunit --testsuite unit handling the unit event returned with error code)
(client_ID and client_secret masked) command with my client id and client secret for sandbox. these credentials work in Postname.
created a file named "CreatePayoutSample.php" with the following code.
"<?php

namespace Sample;

require DIR . '/../vendor/autoload.php';

use PaypalPayoutsSDK\Core\PayPalHttpClient;
use PaypalPayoutsSDK\Core\SandboxEnvironment;
// Creating an environment
$clientId = "AcRivaHqeubISibpYNCVQIZpzHoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "EH9NYd5DudNZ2klWcNkFWclqcsJdReExxxxxxxxxxxxxxxxxxxxxxxxxxx ";

$environment = new SandboxEnvironment($clientId, $clientSecret);
$client = new PayPalHttpClient($environment);

use Sample\PayPalClient;
use PaypalPayoutsSDK\Payouts\PayoutsPostRequest;
use PayPalHttp\HttpException;

class CreatePayoutSample
{

public static function buildRequestBody()
{
return json_decode(
'{
"sender_batch_header":
{
"email_subject": "SDK payouts test txn"
},
"items": [
{
"recipient_type": "EMAIL",
"receiver": "payouts2342@paypal.com",
"note": "Your 1$ payout",
"sender_item_id": "Test_txn_12",
"amount":
{
"currency": "USD",
"value": "1"
}
}]
}',
true
);
}
/**

  • This function can be used to create payout.
    */
    public static function CreatePayout($debug = false)
    {
    try {
    $request = new PayoutsPostRequest();
    $request->body = self::buildRequestBody();
    $client = PayPalClient::client();
    $response = $client->execute($request);
    if ($debug) {
    print "Status Code: {$response->statusCode}\n";
    print "Status: {$response->result->batch_header->batch_status}\n";
    print "Batch ID: {$response->result->batch_header->payout_batch_id}\n";
    print "Links:\n";
    foreach ($response->result->links as $link) {
    print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
    }
    // To toggle printing the whole response body comment/uncomment below line
    echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
    }
    return $response;
    } catch (HttpException $e) {
    //Parse failure response
    echo $e->getMessage() . "\n";
    $error = json_decode($e->getMessage());
    echo $error->message . "\n";
    echo $error->name . "\n";
    echo $error->debug_id . "\n";
    }
    }
    }

if (!count(debug_backtrace())) {
CreatePayoutSample::CreatePayout(true);
}"
When I go to that web address https://www.westernraces.com/paypalpayouts/Payouts-PHP-SDK-master/CreatePayoutSample.php I get page isnt working error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant