Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
61
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/AuthorizeOrder.php
vendored
Normal file
61
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/AuthorizeOrder.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Sample\AuthorizeIntentExamples;
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use PayPalCheckoutSdk\Orders\OrdersAuthorizeRequest;
|
||||
use Sample\PayPalClient;
|
||||
|
||||
|
||||
class AuthorizeOrder
|
||||
{
|
||||
/**
|
||||
* Setting up request body for Authorize. This can be populated with fields as per need. Refer API docs for more details.
|
||||
*
|
||||
*/
|
||||
public static function buildRequestBody()
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
/**
|
||||
* This function can be used to perform authorization on the approved order.
|
||||
* Valid Approved order id should be passed as an argument.
|
||||
*/
|
||||
public static function authorizeOrder($orderId, $debug=false)
|
||||
{
|
||||
$request = new OrdersAuthorizeRequest($orderId);
|
||||
$request->body = self::buildRequestBody();
|
||||
|
||||
$client = PayPalClient::client();
|
||||
$response = $client->execute($request);
|
||||
if ($debug)
|
||||
{
|
||||
print "Status Code: {$response->statusCode}\n";
|
||||
print "Status: {$response->result->status}\n";
|
||||
print "Order ID: {$response->result->id}\n";
|
||||
print "Authorization ID: {$response->result->purchase_units[0]->payments->authorizations[0]->id}\n";
|
||||
print "Links:\n";
|
||||
foreach($response->result->links as $link)
|
||||
{
|
||||
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
print "Authorization Links:\n";
|
||||
foreach($response->result->purchase_units[0]->payments->authorizations[0]->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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an driver function which invokes authorize order.
|
||||
*/
|
||||
if (!count(debug_backtrace()))
|
||||
{
|
||||
AuthorizeOrder::authorizeOrder('1U242387CB956380X', true);
|
||||
}
|
||||
55
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CaptureOrder.php
vendored
Normal file
55
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CaptureOrder.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Sample\AuthorizeIntentExamples;
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use PayPalCheckoutSdk\Payments\AuthorizationsCaptureRequest;
|
||||
use Sample\PayPalClient;
|
||||
|
||||
class CaptureOrder
|
||||
{
|
||||
/**
|
||||
* Below method can be used to build the capture request body.
|
||||
* This request can be updated with required fields as per need.
|
||||
* Please refer API specs for more info.
|
||||
*/
|
||||
public static function buildRequestBody()
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Below function can be used to capture order.
|
||||
* Valid Authorization id should be passed as an argument.
|
||||
*/
|
||||
public static function captureOrder($authorizationId, $debug=false)
|
||||
{
|
||||
$request = new AuthorizationsCaptureRequest($authorizationId);
|
||||
$request->body = self::buildRequestBody();
|
||||
$client = PayPalClient::client();
|
||||
$response = $client->execute($request);
|
||||
|
||||
if ($debug)
|
||||
{
|
||||
print "Status Code: {$response->statusCode}\n";
|
||||
print "Status: {$response->result->status}\n";
|
||||
print "Capture ID: {$response->result->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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Driver function for invoking the capture flow.
|
||||
*/
|
||||
if (!count(debug_backtrace()))
|
||||
{
|
||||
CaptureOrder::captureOrder('18A38324BV5456924', true);
|
||||
}
|
||||
237
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CreateOrder.php
vendored
Normal file
237
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/CreateOrder.php
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
namespace Sample\AuthorizeIntentExamples;
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
|
||||
use Sample\PayPalClient;
|
||||
|
||||
class CreateOrder
|
||||
{
|
||||
/**
|
||||
* Setting up the JSON request body for creating the Order with complete request body. The Intent in the
|
||||
* request body should be set as "AUTHORIZE" for authorize intent flow.
|
||||
*
|
||||
*/
|
||||
private static function buildRequestBody()
|
||||
{
|
||||
return array(
|
||||
'intent' => 'AUTHORIZE',
|
||||
'application_context' =>
|
||||
array(
|
||||
'return_url' => 'https://example.com/return',
|
||||
'cancel_url' => 'https://example.com/cancel',
|
||||
'brand_name' => 'EXAMPLE INC',
|
||||
'locale' => 'en-US',
|
||||
'landing_page' => 'BILLING',
|
||||
'shipping_preference' => 'SET_PROVIDED_ADDRESS',
|
||||
'user_action' => 'PAY_NOW',
|
||||
),
|
||||
'purchase_units' =>
|
||||
array(
|
||||
0 =>
|
||||
array(
|
||||
'reference_id' => 'PUHF',
|
||||
'description' => 'Sporting Goods',
|
||||
'custom_id' => 'CUST-HighFashions',
|
||||
'soft_descriptor' => 'HighFashions',
|
||||
'amount' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '220.00',
|
||||
'breakdown' =>
|
||||
array(
|
||||
'item_total' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '180.00',
|
||||
),
|
||||
'shipping' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '20.00',
|
||||
),
|
||||
'handling' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '10.00',
|
||||
),
|
||||
'tax_total' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '20.00',
|
||||
),
|
||||
'shipping_discount' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '10.00',
|
||||
),
|
||||
),
|
||||
),
|
||||
'items' =>
|
||||
array(
|
||||
0 =>
|
||||
array(
|
||||
'name' => 'T-Shirt',
|
||||
'description' => 'Green XL',
|
||||
'sku' => 'sku01',
|
||||
'unit_amount' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '90.00',
|
||||
),
|
||||
'tax' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '10.00',
|
||||
),
|
||||
'quantity' => '1',
|
||||
'category' => 'PHYSICAL_GOODS',
|
||||
),
|
||||
1 =>
|
||||
array(
|
||||
'name' => 'Shoes',
|
||||
'description' => 'Running, Size 10.5',
|
||||
'sku' => 'sku02',
|
||||
'unit_amount' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '45.00',
|
||||
),
|
||||
'tax' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '5.00',
|
||||
),
|
||||
'quantity' => '2',
|
||||
'category' => 'PHYSICAL_GOODS',
|
||||
),
|
||||
),
|
||||
'shipping' =>
|
||||
array(
|
||||
'method' => 'United States Postal Service',
|
||||
'name' =>
|
||||
array(
|
||||
'full_name' => 'John Doe',
|
||||
),
|
||||
'address' =>
|
||||
array(
|
||||
'address_line_1' => '123 Townsend St',
|
||||
'address_line_2' => 'Floor 6',
|
||||
'admin_area_2' => 'San Francisco',
|
||||
'admin_area_1' => 'CA',
|
||||
'postal_code' => '94107',
|
||||
'country_code' => 'US',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting up the JSON request body for creating the Order with minimum request body. The Intent in the
|
||||
* request body should be set as "AUTHORIZE" for authorize intent flow.
|
||||
*
|
||||
*/
|
||||
private static function buildMinimumRequestBody()
|
||||
{
|
||||
return array(
|
||||
'intent' => 'AUTHORIZE',
|
||||
'application_context' =>
|
||||
array(
|
||||
'return_url' => 'https://example.com/return',
|
||||
'cancel_url' => 'https://example.com/cancel'
|
||||
),
|
||||
'purchase_units' =>
|
||||
array(
|
||||
0 =>
|
||||
array(
|
||||
'amount' =>
|
||||
array(
|
||||
'currency_code' => 'USD',
|
||||
'value' => '220.00'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the sample function which can be used to create an order. It uses the
|
||||
* JSON body returned by buildRequestBody() to create an new Order.
|
||||
*/
|
||||
public static function createOrder($debug=false)
|
||||
{
|
||||
$request = new OrdersCreateRequest();
|
||||
$request->headers["prefer"] = "return=representation";
|
||||
$request->body = CreateOrder::buildRequestBody();
|
||||
|
||||
$client = PayPalClient::client();
|
||||
$response = $client->execute($request);
|
||||
if ($debug)
|
||||
{
|
||||
print "Status Code: {$response->statusCode}\n";
|
||||
print "Status: {$response->result->status}\n";
|
||||
print "Order ID: {$response->result->id}\n";
|
||||
print "Intent: {$response->result->intent}\n";
|
||||
print "Links:\n";
|
||||
foreach($response->result->links as $link)
|
||||
{
|
||||
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
|
||||
print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n";
|
||||
|
||||
// To toggle printing the whole response body comment/uncomment below line
|
||||
echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
|
||||
}
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the sample function which can be used to create an order. It uses the
|
||||
* JSON body returned by buildMinimumRequestBody() to create an new Order.
|
||||
*/
|
||||
public static function createOrderWithMinimumBody($debug=false)
|
||||
{
|
||||
$request = new OrdersCreateRequest();
|
||||
$request->headers["prefer"] = "return=representation";
|
||||
$request->body = CreateOrder::buildMinimumRequestBody();
|
||||
|
||||
$client = PayPalClient::client();
|
||||
$response = $client->execute($request);
|
||||
if ($debug)
|
||||
{
|
||||
print "Order With Minimum Body\n";
|
||||
print "Status Code: {$response->statusCode}\n";
|
||||
print "Status: {$response->result->status}\n";
|
||||
print "Order ID: {$response->result->id}\n";
|
||||
print "Intent: {$response->result->intent}\n";
|
||||
print "Links:\n";
|
||||
foreach($response->result->links as $link)
|
||||
{
|
||||
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
|
||||
print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n";
|
||||
|
||||
// To toggle printing the whole response body comment/uncomment below line
|
||||
echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
|
||||
}
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!count(debug_backtrace()))
|
||||
{
|
||||
CreateOrder::createOrder(true);
|
||||
CreateOrder::createOrderWithMinimumBody(true);
|
||||
}
|
||||
82
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php
vendored
Normal file
82
vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Sample\AuthorizeIntentExamples\CreateOrder;
|
||||
use Sample\AuthorizeIntentExamples\AuthorizeOrder;
|
||||
use Sample\AuthorizeIntentExamples\CaptureOrder;
|
||||
use Sample\RefundOrder;
|
||||
|
||||
$order = CreateOrder::createOrder();
|
||||
|
||||
print "Creating Order...\n";
|
||||
$orderId = "";
|
||||
if ($order->statusCode == 201)
|
||||
{
|
||||
$orderId = $order->result->id;
|
||||
print "Links:\n";
|
||||
for ($i = 0; $i < count($order->result->links); ++$i)
|
||||
{
|
||||
$link = $order->result->links[$i];
|
||||
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
print "Created Successfully\n";
|
||||
print "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n";
|
||||
}
|
||||
else {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$handle = fopen ("php://stdin","r");
|
||||
$line = fgets($handle);
|
||||
fclose($handle);
|
||||
|
||||
print "Authorizing Order...\n";
|
||||
$response = AuthorizeOrder::authorizeOrder($orderId);
|
||||
$authId = "";
|
||||
|
||||
if ($response->statusCode == 201)
|
||||
{
|
||||
print "Authorized Successfully\n";
|
||||
$authId = $response->result->purchase_units[0]->payments->authorizations[0]->id;
|
||||
}
|
||||
else {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print "\nCapturing Order...\n";
|
||||
$response = CaptureOrder::captureOrder($authId);
|
||||
if ($response->statusCode == 201)
|
||||
{
|
||||
print "Captured Successfully\n";
|
||||
print "Status Code: {$response->statusCode}\n";
|
||||
print "Status: {$response->result->status}\n";
|
||||
$captureId = $response->result->id;
|
||||
print "Capture ID: {$captureId}\n";
|
||||
print "Links:\n";
|
||||
for ($i = 0; $i < count($response->result->links); ++$i){
|
||||
$link = $response->result->links[$i];
|
||||
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print "\nRefunding Order...\n";
|
||||
$response = RefundOrder::refundOrder($captureId);
|
||||
if ($response->statusCode == 201)
|
||||
{
|
||||
print "Refunded Successfully\n";
|
||||
print "Status Code: {$response->statusCode}\n";
|
||||
print "Status: {$response->result->status}\n";
|
||||
print "Refund ID: {$response->result->id}\n";
|
||||
print "Links:\n";
|
||||
for ($i = 0; $i < count($response->result->links); ++$i){
|
||||
$link = $response->result->links[$i];
|
||||
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user