Skip to content

Instantly share code, notes, and snippets.

@kiramishima
Last active March 21, 2018 00:09
Show Gist options
  • Save kiramishima/33f3a40798b953e82fc0637b0d346c67 to your computer and use it in GitHub Desktop.
Save kiramishima/33f3a40798b953e82fc0637b0d346c67 to your computer and use it in GitHub Desktop.
Paypal Payout PHP (Only for USA )
<?php
$apiContext = new ApiContext(
new OAuthTokenCredential(
env('PAYPAL_CLIENT_ID'), // ClientID
env('PAYPAL_CLIENT_SECRET') // ClientSecret
)
);
/*$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'DEBUG'
)
);*/
$payouts = new Payout();
$senderBatchHeader = new PayoutSenderBatchHeader();
// #### Batch Header Instance
$senderBatchHeader->setSenderBatchId(uniqid())
->setEmailSubject("You have a payment");
// #### Sender Item
// Please note that if you are using single payout with sync mode, you can only pass one Item in the request
$senderItem = new PayoutItem();
$senderItem->setRecipientType('Email')
->setNote('Thanks for your patronage!')
->setReceiver('shirt-supplier-one@gmail.com')
->setSenderItemId("item_1" . uniqid())
->setAmount(new \PayPal\Api\Currency('{
"value":"10.0",
"currency":"MXN"
}'));
$payouts->setSenderBatchHeader($senderBatchHeader)
->addItem($senderItem);
// For Sample Purposes Only.
// $request = clone $payouts;
// ### Create Payout
try {
$output = $payouts->createSynchronous($apiContext);
print "Created Single Synchronous Payout"."Payout";
var_dump($output->getBatchHeader()->getPayoutBatchId());
// var_dump($request);
var_dump($output);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
print "Created Single Synchronous Payout". "Payout";
// var_dump($request);
var_dump($ex);
// exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment