diff --git a/README.md b/README.md index fcb73bba..25540fe4 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,11 @@ __Welcome to PayPal PHP SDK__. This repository contains PayPal's PHP SDK and sam - PHP 5.3 or above - [curl](https://secure.php.net/manual/en/book.curl.php), [json](https://secure.php.net/manual/en/book.json.php) & [openssl](https://secure.php.net/manual/en/book.openssl.php) extensions must be enabled + +## Direct Credit Card Support +[Braintree Direct](https://www.braintreepayments.com/products/braintree-direct) is PayPal's preferred integration solution for accepting direct credit card payments in your mobile app or website. Braintree, a PayPal service, is the easiest way to accept credit cards, PayPal, and many other payment methods. + + ## License Read [License](LICENSE) for more licensing information. diff --git a/sample/billing/CreateBillingAgreementWithCreditCard.php b/sample/billing/CreateBillingAgreementWithCreditCard.php deleted file mode 100644 index 0eadee1a..00000000 --- a/sample/billing/CreateBillingAgreementWithCreditCard.php +++ /dev/null @@ -1,111 +0,0 @@ -setName('DPRP') - ->setDescription('Payment with credit Card') - ->setStartDate('2019-06-17T9:45:04Z'); - -// Add Plan ID -// Please note that the plan Id should be only set in this case. -$plan = new Plan(); -$plan->setId($createdPlan->getId()); -$agreement->setPlan($plan); - -// Add Payer -$payer = new Payer(); -$payer->setPaymentMethod('credit_card') - ->setPayerInfo(new PayerInfo(array('email' => 'jaypatel512-facilitator@hotmail.com'))); - -// Add Credit Card to Funding Instruments -$card = new CreditCard(); -$card->setType('visa') - ->setNumber('4491759698858890') - ->setExpireMonth('12') - ->setExpireYear('2017') - ->setCvv2('128'); - -$fundingInstrument = new FundingInstrument(); -$fundingInstrument->setCreditCard($card); -$payer->setFundingInstruments(array($fundingInstrument)); -//Add Payer to Agreement -$agreement->setPayer($payer); - -// Add Shipping Address -$shippingAddress = new ShippingAddress(); -$shippingAddress->setLine1('111 First Street') - ->setCity('Saratoga') - ->setState('CA') - ->setPostalCode('95070') - ->setCountryCode('US'); -$agreement->setShippingAddress($shippingAddress); - -// For Sample Purposes Only. -$request = clone $agreement; - -// ### Create Agreement -try { - // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet. - $agreement = $agreement->create($apiContext); -} catch (Exception $ex) { - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex); - exit(1); -} - - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $agreement); - -return $agreement; diff --git a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html deleted file mode 100644 index e833cd26..00000000 --- a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html +++ /dev/null @@ -1,81 +0,0 @@ -billing/CreateBillingAgreementWithCreditCard
billing/CreateBillingAgreementWithCreditCard.php
<?php

Create Billing Agreement with Credit Card as Payment Source

-

This sample code demonstrate how you can create a billing agreement, as documented here at: -https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement -API used: /v1/payments/billing-agreements

Retrieving the Plan from the Create Update Sample. This would be used to -define Plan information to create an agreement. Make sure the plan you are using is in active state.

/** @var Plan $createdPlan */ -$createdPlan = require 'UpdatePlan.php'; - -use PayPal\Api\Agreement; -use PayPal\Api\CreditCard; -use PayPal\Api\FundingInstrument; -use PayPal\Api\Payer; -use PayPal\Api\PayerInfo; -use PayPal\Api\PaymentCard; -use PayPal\Api\Plan; -use PayPal\Api\ShippingAddress; - -/* Create a new instance of Agreement object -{ - "name": "DPRP", - "description": "Payment with credit Card ", - "start_date": "2015-06-17T9:45:04Z", - "plan": { - "id": "P-1WJ68935LL406420PUTENA2I" - }, - "shipping_address": { - "line1": "111 First Street", - "city": "Saratoga", - "state": "CA", - "postal_code": "95070", - "country_code": "US" - }, - "payer": { - "payment_method": "credit_card", - "payer_info": { - "email": "jaypatel512-facilitator@hotmail.com" - }, - "funding_instruments": [ - { - "credit_card": { - "type": "visa", - "number": "4417119669820331", - "expire_month": "12", - "expire_year": "2017", - "cvv2": "128" - } - } - ] - } -}*/ -$agreement = new Agreement(); - -$agreement->setName('DPRP') - ->setDescription('Payment with credit Card') - ->setStartDate('2019-06-17T9:45:04Z');

Add Plan ID -Please note that the plan Id should be only set in this case.

$plan = new Plan(); -$plan->setId($createdPlan->getId()); -$agreement->setPlan($plan);

Add Payer

$payer = new Payer(); -$payer->setPaymentMethod('credit_card') - ->setPayerInfo(new PayerInfo(array('email' => 'jaypatel512-facilitator@hotmail.com')));

Add Credit Card to Funding Instruments

$card = new CreditCard(); -$card->setType('visa') - ->setNumber('4491759698858890') - ->setExpireMonth('12') - ->setExpireYear('2017') - ->setCvv2('128'); - -$fundingInstrument = new FundingInstrument(); -$fundingInstrument->setCreditCard($card); -$payer->setFundingInstruments(array($fundingInstrument)); -//Add Payer to Agreement -$agreement->setPayer($payer);

Add Shipping Address

$shippingAddress = new ShippingAddress(); -$shippingAddress->setLine1('111 First Street') - ->setCity('Saratoga') - ->setState('CA') - ->setPostalCode('95070') - ->setCountryCode('US'); -$agreement->setShippingAddress($shippingAddress);

For Sample Purposes Only.

$request = clone $agreement;

Create Agreement

try {

Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.

$agreement = $agreement->create($apiContext); -} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex); - exit(1); -}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $agreement); - -return $agreement;
diff --git a/sample/doc/payments/AuthorizationCapture.html b/sample/doc/payments/AuthorizationCapture.html index d4d29c5c..ec08714f 100644 --- a/sample/doc/payments/AuthorizationCapture.html +++ b/sample/doc/payments/AuthorizationCapture.html @@ -2,15 +2,12 @@

This sample code demonstrates how you can capture a previously authorized payment. API used: /v1/payments/payment -https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization

/** @var Authorization $authorization */ -$authorization = require 'GetAuthorization.php'; -use PayPal\Api\Amount; +https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization

use PayPal\Api\Amount; use PayPal\Api\Authorization; -use PayPal\Api\Capture;

Capture Payment

+use PayPal\Api\Capture;

Replace $authorizationId with any static Id you might already have.

$authorizationId = "<your authorization id here>";

Capture Payment

You can capture and process a previously created authorization by invoking the $authorization->capture method -with a valid ApiContext (See bootstrap.php for more on ApiContext)

try { - $authId = $authorization->getId(); +with a valid ApiContext (See bootstrap.php for more on ApiContext)

try {

Retrieve the authorization

$authorization = Authorization::get($authorizationId, $apiContext); $amt = new Amount(); $amt->setCurrency("USD") @@ -23,4 +20,4 @@ exit(1); }

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Capture Payment", "Authorization", $getCapture->getId(), $capture, $getCapture); -return $getCapture;
+return $getCapture; \ No newline at end of file diff --git a/sample/doc/payments/AuthorizePayment.html b/sample/doc/payments/AuthorizePayment.html deleted file mode 100644 index 13a70988..00000000 --- a/sample/doc/payments/AuthorizePayment.html +++ /dev/null @@ -1,64 +0,0 @@ -payments/AuthorizePayment
payments/AuthorizePayment.php
<?php

Authorize Payment

-

This sample code demonstrates how you can authorize a payment. -API used: /v1/payments/authorization -https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment

require __DIR__ . '/../bootstrap.php'; - -use PayPal\Api\Address; -use PayPal\Api\Amount; -use PayPal\Api\FundingInstrument; -use PayPal\Api\Payer; -use PayPal\Api\Payment; -use PayPal\Api\PaymentCard; -use PayPal\Api\Transaction;

The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment -to correct setting. In this case, it would be 'authorize'

$addr = new Address(); -$addr->setLine1("3909 Witmer Road") - ->setLine2("Niagara Falls") - ->setCity("Niagara Falls") - ->setState("NY") - ->setPostalCode("14305") - ->setCountryCode("US") - ->setPhone("716-298-1822"); - -$paymentCard = new PaymentCard(); -$paymentCard->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("Shopper") - ->setBillingCountry("US") - ->setBillingAddress($addr); - -$fi = new FundingInstrument(); -$fi->setPaymentCard($paymentCard); - -$payer = new Payer(); -$payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); - -$amount = new Amount(); -$amount->setCurrency("USD") - ->setTotal(1); - -$transaction = new Transaction(); -$transaction->setAmount($amount) - ->setDescription("Payment description."); - -$payment = new Payment();

Setting intent to authorize creates a payment -authorization. Setting it to sale creates actual payment

$payment->setIntent("authorize") - ->setPayer($payer) - ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

-

Create a payment by calling the payment->create() method -with a valid ApiContext (See bootstrap.php for more on ApiContext) -The return object contains the state.

try { - $payment->create($apiContext); -} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex); - exit(1); -}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment); - -$transactions = $payment->getTransactions(); -$relatedResources = $transactions[0]->getRelatedResources(); -$authorization = $relatedResources[0]->getAuthorization(); - -return $authorization;
diff --git a/sample/doc/payments/CreatePaymentUsingSavedCard.html b/sample/doc/payments/CreatePaymentUsingSavedCard.html deleted file mode 100644 index 129a539c..00000000 --- a/sample/doc/payments/CreatePaymentUsingSavedCard.html +++ /dev/null @@ -1,75 +0,0 @@ -payments/CreatePaymentUsingSavedCard
payments/CreatePaymentUsingSavedCard.php
<?php

Create payment using a saved credit card

-

This sample code demonstrates how you can process a -Payment using a previously stored credit card token. -API used: /v1/payments/payment

/** @var CreditCard $card */ -$card = require __DIR__ . '/../vault/CreateCreditCard.php'; -use PayPal\Api\Amount; -use PayPal\Api\CreditCard; -use PayPal\Api\CreditCardToken; -use PayPal\Api\Details; -use PayPal\Api\FundingInstrument; -use PayPal\Api\Item; -use PayPal\Api\ItemList; -use PayPal\Api\Payer; -use PayPal\Api\Payment; -use PayPal\Api\Transaction;

Credit card token

-

Saved credit card id from a previous call to -CreateCreditCard.php

$creditCardToken = new CreditCardToken(); -$creditCardToken->setCreditCardId($card->getId());

FundingInstrument

-

A resource representing a Payer's funding instrument. -For stored credit card payments, set the CreditCardToken -field on this object.

$fi = new FundingInstrument(); -$fi->setCreditCardToken($creditCardToken);

Payer

-

A resource representing a Payer that funds a payment -For stored credit card payments, set payment method -to 'credit_card'.

$payer = new Payer(); -$payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi));

Itemized information

-

(Optional) Lets you specify item wise -information

$item1 = new Item(); -$item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice(7.5); -$item2 = new Item(); -$item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice(2); - -$itemList = new ItemList(); -$itemList->setItems(array($item1, $item2));

Additional payment details

-

Use this optional field to set additional -payment information such as tax, shipping -charges etc.

$details = new Details(); -$details->setShipping(1.2) - ->setTax(1.3) - ->setSubtotal(17.5);

Amount

-

Lets you specify a payment amount. -You can also specify additional details -such as shipping, tax.

$amount = new Amount(); -$amount->setCurrency("USD") - ->setTotal(20) - ->setDetails($details);

Transaction

-

A transaction defines the contract of a -payment - what is the payment for and who -is fulfilling it.

$transaction = new Transaction(); -$transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description") - ->setInvoiceNumber(uniqid());

Payment

-

A Payment Resource; create one using -the above types and intent set to 'sale'

$payment = new Payment(); -$payment->setIntent("sale") - ->setPayer($payer) - ->setTransactions(array($transaction));

For Sample Purposes Only.

$request = clone $payment;

Create Payment

-

Create a payment by calling the 'create' method -passing it a valid apiContext. -(See bootstrap.php for more on ApiContext) -The return object contains the state.

try { - $payment->create($apiContext); -} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex); - exit(1); -}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment); - -return $card;
diff --git a/sample/doc/payments/GetAuthorization.html b/sample/doc/payments/GetAuthorization.html index cc8aa035..020c9014 100644 --- a/sample/doc/payments/GetAuthorization.html +++ b/sample/doc/payments/GetAuthorization.html @@ -1,10 +1,7 @@ payments/GetAuthorization
payments/GetAuthorization.php
<?php

GetAuthorization

This sample code demonstrates how you can get details of an authorized payment. -API used: /v1/payments/authorization/<$authorizationId>

/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php'; -$authorizationId = $authorization->getId(); -use PayPal\Api\Authorization;

GetAuthorization

+API used: /v1/payments/authorization/<$authorizationId>

use PayPal\Api\Authorization;

Replace $authorizationId with any static Id you might already have.

$authorizationId = "<your authorization id here>";

GetAuthorization

You can retrieve info about an Authorization by invoking the Authorization::get method with a valid ApiContext (See bootstrap.php for more on ApiContext) @@ -13,4 +10,4 @@ exit(1); }

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Get Authorization", "Authorization", $authorizationId, null, $result); -return $result;
+return $result; \ No newline at end of file diff --git a/sample/doc/payments/GetCapture.html b/sample/doc/payments/GetCapture.html index 1047a645..d8906dcd 100644 --- a/sample/doc/payments/GetCapture.html +++ b/sample/doc/payments/GetCapture.html @@ -1,13 +1,10 @@ payments/GetCapture
payments/GetCapture.php
<?php

GetCapture

This sample code demonstrates how you can lookup the details of a captured payment. -API used: /v1/payments/capture/<$captureId>

/** @var Capture $request */ -$request = require 'AuthorizationCapture.php'; - -use PayPal\Api\Capture;

Retrieve Capture details

+API used: /v1/payments/capture/<$captureId>

use PayPal\Api\Capture;

Replace $captureId with any static Id you might already have.

$captureId = "<your authorization id here>";

Retrieve Capture details

You can look up a capture by invoking the Capture::get method with a valid ApiContext (See bootstrap.php for more on ApiContext)

try { - $capture = Capture::get($request->getId(), $apiContext); -} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex); + $capture = Capture::get($captureId, $apiContext); +} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Get Captured Payment", "Capture", $captureId, null, $ex); exit(1); -}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture);
+}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture);
\ No newline at end of file diff --git a/sample/doc/payments/GetPayment.html b/sample/doc/payments/GetPayment.html index e4bb1a29..f2e17fcf 100644 --- a/sample/doc/payments/GetPayment.html +++ b/sample/doc/payments/GetPayment.html @@ -6,10 +6,8 @@ use to filter, and paginate through the payments list. API used: GET /v1/payments/payments

/** @var Payment $createdPayment */ -$createdPayment = require 'CreatePayment.php'; -use PayPal\Api\Payment; -$paymentId = $createdPayment->getId();

Retrieve payment

+use PayPal\Api\Payment;

Replace $paymentId with any static Id you might already have.

$paymentId = "<your paymentid here>";

Retrieve payment

Retrieve the payment object by calling the static get method on the Payment class by passing a valid @@ -20,4 +18,4 @@ exit(1); }

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment); -return $payment;
+return $payment; \ No newline at end of file diff --git a/sample/doc/payments/Reauthorization.html b/sample/doc/payments/Reauthorization.html index 6d7898ed..c1b600a1 100644 --- a/sample/doc/payments/Reauthorization.html +++ b/sample/doc/payments/Reauthorization.html @@ -1,19 +1,22 @@ payments/Reauthorization
payments/Reauthorization.php
<?php

Reauthorization Sample

This sample code demonstrates how you can reauthorize a PayPal account payment. -API used: v1/payments/authorization/{authorization_id}/reauthorize

/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php'; -use PayPal\Api\Amount; +API used: v1/payments/authorization/{authorization_id}/reauthorize

use PayPal\Api\Amount; use PayPal\Api\Authorization;

Reauthorization

Reauthorization is available only for PayPal account payments and not for credit card payments.

You can reauthorize a payment only once 4 to 29 days after the 3-day honor period for the original authorization -has expired.

try { +has expired.

Replace $authorizationId with any static Id you might already have.

$authorizationId = "<your authorization id here>"; + +try { + + $authorization = Authorization::get($authorizationId, $apiContext); + $amount = new Amount(); $amount->setCurrency("USD"); - $amount->setTotal(1);

Reauthorize with amount being reauthorized

$authorization->setAmount($amount); + $amount->setTotal(1200);

Reauthorize with amount being reauthorized

$authorization->setAmount($amount); $reAuthorization = $authorization->reauthorize($apiContext); } catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Reauthorize Payment", "Payment", null, null, $ex); exit(1); -}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization);
+}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorizationId, null, $reAuthorization);
\ No newline at end of file diff --git a/sample/doc/payments/RefundCapture.html b/sample/doc/payments/RefundCapture.html index 546dd9c8..228a2c71 100644 --- a/sample/doc/payments/RefundCapture.html +++ b/sample/doc/payments/RefundCapture.html @@ -2,19 +2,19 @@

This sample code demonstrates how you can process a refund on a Captured transaction. API used: /v1/payments/capture/{}/refund

/** @var Capture $capture */ -$capture = require 'AuthorizationCapture.php'; + use PayPal\Api\Capture; use PayPal\Api\Refund; use PayPal\Api\RefundRequest;

Refund

Create a refund object indicating -refund amount and call the refund method

$refundRequest = new RefundRequest(); -$refundRequest->setAmount($amt); +refund amount and call the refund method

Replace $captureId with any static Id you might already have.

$captureId = "<your authorization id here>"; + + try {

Create a new apiContext object so we send a new -PayPal-Request-Id (idempotency) header for this resource

$apiContext = getApiContext($clientId, $clientSecret); +PayPal-Request-Id (idempotency) header for this resource

$apiContext = getApiContext($clientId, $clientSecret);

Retrieve Capture details

$capture = Capture::get($captureId, $apiContext);

Refund the Capture

$captureRefund = $capture->refundCapturedPayment($refundRequest, $apiContext); - $captureRefund = $capture->refundCapturedPayment($refundRequest, $apiContext); } catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Refund Capture", "Capture", null, $refundRequest, $ex); exit(1); -}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refundRequest, $captureRefund);
+}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refundRequest, $captureRefund);
\ No newline at end of file diff --git a/sample/doc/payments/VoidAuthorization.html b/sample/doc/payments/VoidAuthorization.html index 35947760..ffdb650f 100644 --- a/sample/doc/payments/VoidAuthorization.html +++ b/sample/doc/payments/VoidAuthorization.html @@ -1,8 +1,8 @@ payments/VoidAuthorization
payments/VoidAuthorization.php
<?php

VoidAuthorization

This sample code demonstrates how you can void an authorized payment. -API used: /v1/payments/authorization/<{authorizationid}>/void"

/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php';

Replace $authorizationid with any static Id you might already have. It will do a void on it

$authorizationId = '1BF65516U6866543H'; // $authorization->getId(); +API used: /v1/payments/authorization/<{authorizationid}>/void"

Replace $authorizationId with any static Id you might already have.

$authorizationId = "<your authorization id here>"; + use PayPal\Api\Authorization;

VoidAuthorization

You can void a previously authorized payment by invoking the $authorization->void method @@ -11,4 +11,4 @@ exit(1); }

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Void Authorization", "Authorization", $voidedAuth->getId(), null, $voidedAuth); -return $voidedAuth;
+return $voidedAuth; \ No newline at end of file diff --git a/sample/index.php b/sample/index.php index 9bf178fb..000e7209 100644 --- a/sample/index.php +++ b/sample/index.php @@ -268,17 +268,6 @@ class="fa fa-file-code-o"> -
  • -
    -
    Payments using credit card information
    - -
    -
  • Payments to a 3rd-Party Payee
    @@ -290,18 +279,7 @@ class="fa fa-file-code-o">
  • -
  • -
    -
    Payments using saved credit card (using Vault APIs)
    - -
    -
  • +
  • @@ -431,10 +409,10 @@ class="fa fa-file-code-o"> @@ -758,19 +736,6 @@ class="fa fa-file-code-o">
  • -
  • -
    -
    Create Billing Agreement With Credit Card
    - -
    -
  • Create Billing Agreement With PayPal
    diff --git a/sample/payments/AuthorizationCapture.php b/sample/payments/AuthorizationCapture.php index 0cbe9c0d..03cb7156 100644 --- a/sample/payments/AuthorizationCapture.php +++ b/sample/payments/AuthorizationCapture.php @@ -5,18 +5,22 @@ // API used: /v1/payments/payment // https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization -/** @var Authorization $authorization */ -$authorization = require 'GetAuthorization.php'; use PayPal\Api\Amount; use PayPal\Api\Authorization; use PayPal\Api\Capture; + +// Replace $authorizationId with any static Id you might already have. +$authorizationId = ""; + // ### Capture Payment // You can capture and process a previously created authorization // by invoking the $authorization->capture method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { - $authId = $authorization->getId(); + + // Retrieve the authorization + $authorization = Authorization::get($authorizationId, $apiContext); $amt = new Amount(); $amt->setCurrency("USD") diff --git a/sample/payments/AuthorizePayment.php b/sample/payments/AuthorizePayment.php deleted file mode 100644 index 61c06b5c..00000000 --- a/sample/payments/AuthorizePayment.php +++ /dev/null @@ -1,84 +0,0 @@ -setLine1("3909 Witmer Road") - ->setLine2("Niagara Falls") - ->setCity("Niagara Falls") - ->setState("NY") - ->setPostalCode("14305") - ->setCountryCode("US") - ->setPhone("716-298-1822"); - -$paymentCard = new PaymentCard(); -$paymentCard->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("Shopper") - ->setBillingCountry("US") - ->setBillingAddress($addr); - -$fi = new FundingInstrument(); -$fi->setPaymentCard($paymentCard); - -$payer = new Payer(); -$payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); - -$amount = new Amount(); -$amount->setCurrency("USD") - ->setTotal(1); - -$transaction = new Transaction(); -$transaction->setAmount($amount) - ->setDescription("Payment description."); - -$payment = new Payment(); - -// Setting intent to authorize creates a payment -// authorization. Setting it to sale creates actual payment -$payment->setIntent("authorize") - ->setPayer($payer) - ->setTransactions(array($transaction)); - -// For Sample Purposes Only. -$request = clone $payment; - -// ### Create Payment -// Create a payment by calling the payment->create() method -// with a valid ApiContext (See bootstrap.php for more on `ApiContext`) -// The return object contains the state. -try { - $payment->create($apiContext); -} catch (Exception $ex) { - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex); - exit(1); -} - -// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment); - -$transactions = $payment->getTransactions(); -$relatedResources = $transactions[0]->getRelatedResources(); -$authorization = $relatedResources[0]->getAuthorization(); - -return $authorization; diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php deleted file mode 100644 index ba83f410..00000000 --- a/sample/payments/CreatePayment.php +++ /dev/null @@ -1,125 +0,0 @@ -setType("visa") - ->setNumber("4669424246660779") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setBillingCountry("US") - ->setLastName("Shopper"); - -// ### FundingInstrument -// A resource representing a Payer's funding instrument. -// For direct credit card payments, set the CreditCard -// field on this object. -$fi = new FundingInstrument(); -$fi->setPaymentCard($card); - -// ### Payer -// A resource representing a Payer that funds a payment -// For direct credit card payments, set payment method -// to 'credit_card' and add an array of funding instruments. -$payer = new Payer(); -$payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); - -// ### Itemized information -// (Optional) Lets you specify item wise -// information -$item1 = new Item(); -$item1->setName('Ground Coffee 40 oz') - ->setDescription('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setTax(0.3) - ->setPrice(7.50); -$item2 = new Item(); -$item2->setName('Granola bars') - ->setDescription('Granola Bars with Peanuts') - ->setCurrency('USD') - ->setQuantity(5) - ->setTax(0.2) - ->setPrice(2); - -$itemList = new ItemList(); -$itemList->setItems(array($item1, $item2)); - -// ### Additional payment details -// Use this optional field to set additional -// payment information such as tax, shipping -// charges etc. -$details = new Details(); -$details->setShipping(1.2) - ->setTax(1.3) - ->setSubtotal(17.5); - -// ### Amount -// Lets you specify a payment amount. -// You can also specify additional details -// such as shipping, tax. -$amount = new Amount(); -$amount->setCurrency("USD") - ->setTotal(20) - ->setDetails($details); - -// ### Transaction -// A transaction defines the contract of a -// payment - what is the payment for and who -// is fulfilling it. -$transaction = new Transaction(); -$transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description") - ->setInvoiceNumber(uniqid()); - -// ### Payment -// A Payment Resource; create one using -// the above types and intent set to sale 'sale' -$payment = new Payment(); -$payment->setIntent("sale") - ->setPayer($payer) - ->setTransactions(array($transaction)); - -// For Sample Purposes Only. -$request = clone $payment; - -// ### Create Payment -// Create a payment by calling the payment->create() method -// with a valid ApiContext (See bootstrap.php for more on `ApiContext`) -// The return object contains the state. -try { - $payment->create($apiContext); -} catch (Exception $ex) { - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using Step 4, on this link, and using it.', 'Payment', null, $request, $ex); - exit(1); -} - -// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment); - -return $payment; diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php deleted file mode 100644 index 115bc65b..00000000 --- a/sample/payments/CreatePaymentUsingSavedCard.php +++ /dev/null @@ -1,115 +0,0 @@ -setCreditCardId($card->getId()); - -// ### FundingInstrument -// A resource representing a Payer's funding instrument. -// For stored credit card payments, set the CreditCardToken -// field on this object. -$fi = new FundingInstrument(); -$fi->setCreditCardToken($creditCardToken); - -// ### Payer -// A resource representing a Payer that funds a payment -// For stored credit card payments, set payment method -// to 'credit_card'. -$payer = new Payer(); -$payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); - -// ### Itemized information -// (Optional) Lets you specify item wise -// information -$item1 = new Item(); -$item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice(7.5); -$item2 = new Item(); -$item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice(2); - -$itemList = new ItemList(); -$itemList->setItems(array($item1, $item2)); - -// ### Additional payment details -// Use this optional field to set additional -// payment information such as tax, shipping -// charges etc. -$details = new Details(); -$details->setShipping(1.2) - ->setTax(1.3) - ->setSubtotal(17.5); - -// ### Amount -// Lets you specify a payment amount. -// You can also specify additional details -// such as shipping, tax. -$amount = new Amount(); -$amount->setCurrency("USD") - ->setTotal(20) - ->setDetails($details); - -// ### Transaction -// A transaction defines the contract of a -// payment - what is the payment for and who -// is fulfilling it. -$transaction = new Transaction(); -$transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description") - ->setInvoiceNumber(uniqid()); - -// ### Payment -// A Payment Resource; create one using -// the above types and intent set to 'sale' -$payment = new Payment(); -$payment->setIntent("sale") - ->setPayer($payer) - ->setTransactions(array($transaction)); - - -// For Sample Purposes Only. -$request = clone $payment; - -// ###Create Payment -// Create a payment by calling the 'create' method -// passing it a valid apiContext. -// (See bootstrap.php for more on `ApiContext`) -// The return object contains the state. -try { - $payment->create($apiContext); -} catch (Exception $ex) { - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex); - exit(1); -} - -// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment); - -return $card; diff --git a/sample/payments/GetAuthorization.php b/sample/payments/GetAuthorization.php index 674bdf40..7a745715 100644 --- a/sample/payments/GetAuthorization.php +++ b/sample/payments/GetAuthorization.php @@ -3,12 +3,13 @@ // This sample code demonstrates how you can get details // of an authorized payment. // API used: /v1/payments/authorization/<$authorizationId> - -/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php'; -$authorizationId = $authorization->getId(); use PayPal\Api\Authorization; + +// Replace $authorizationId with any static Id you might already have. +$authorizationId = ""; + + // ### GetAuthorization // You can retrieve info about an Authorization // by invoking the Authorization::get method diff --git a/sample/payments/GetCapture.php b/sample/payments/GetCapture.php index 01333f43..1076f44f 100644 --- a/sample/payments/GetCapture.php +++ b/sample/payments/GetCapture.php @@ -4,19 +4,19 @@ // of a captured payment. // API used: /v1/payments/capture/<$captureId> -/** @var Capture $request */ -$request = require 'AuthorizationCapture.php'; - use PayPal\Api\Capture; +// Replace $captureId with any static Id you might already have. +$captureId = ""; + // ### Retrieve Capture details // You can look up a capture by invoking the Capture::get method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { - $capture = Capture::get($request->getId(), $apiContext); + $capture = Capture::get($captureId, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex); + ResultPrinter::printError("Get Captured Payment", "Capture", $captureId, null, $ex); exit(1); } diff --git a/sample/payments/GetPayment.php b/sample/payments/GetPayment.php index c77335f0..776d074a 100644 --- a/sample/payments/GetPayment.php +++ b/sample/payments/GetPayment.php @@ -9,10 +9,11 @@ // API used: GET /v1/payments/payments /** @var Payment $createdPayment */ -$createdPayment = require 'CreatePayment.php'; + use PayPal\Api\Payment; -$paymentId = $createdPayment->getId(); +// Replace $paymentId with any static Id you might already have. +$paymentId = ""; // ### Retrieve payment // Retrieve the payment object by calling the diff --git a/sample/payments/Reauthorization.php b/sample/payments/Reauthorization.php index 3dfd462a..3a5e7d4f 100644 --- a/sample/payments/Reauthorization.php +++ b/sample/payments/Reauthorization.php @@ -3,8 +3,7 @@ // This sample code demonstrates how you can reauthorize a PayPal // account payment. // API used: v1/payments/authorization/{authorization_id}/reauthorize -/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php'; + use PayPal\Api\Amount; use PayPal\Api\Authorization; @@ -16,10 +15,16 @@ // days after the 3-day honor period for the original authorization // has expired. +// Replace $authorizationId with any static Id you might already have. +$authorizationId = ""; + try { + + $authorization = Authorization::get($authorizationId, $apiContext); + $amount = new Amount(); $amount->setCurrency("USD"); - $amount->setTotal(1); + $amount->setTotal(1200); // ### Reauthorize with amount being reauthorized $authorization->setAmount($amount); @@ -32,4 +37,4 @@ } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY -ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization); +ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorizationId, null, $reAuthorization); diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php index 8d47777f..3a7a8d9a 100644 --- a/sample/payments/RefundCapture.php +++ b/sample/payments/RefundCapture.php @@ -4,7 +4,7 @@ // process a refund on a Captured transaction. // API used: /v1/payments/capture/{}/refund /** @var Capture $capture */ -$capture = require 'AuthorizationCapture.php'; + use PayPal\Api\Capture; use PayPal\Api\Refund; @@ -14,15 +14,22 @@ // Create a refund object indicating // refund amount and call the refund method -$refundRequest = new RefundRequest(); -$refundRequest->setAmount($amt); +// Replace $captureId with any static Id you might already have. +$captureId = ""; + + try { // Create a new apiContext object so we send a new // PayPal-Request-Id (idempotency) header for this resource $apiContext = getApiContext($clientId, $clientSecret); + // ### Retrieve Capture details + $capture = Capture::get($captureId, $apiContext); + + // ### Refund the Capture $captureRefund = $capture->refundCapturedPayment($refundRequest, $apiContext); + } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Refund Capture", "Capture", null, $refundRequest, $ex); diff --git a/sample/payments/VoidAuthorization.php b/sample/payments/VoidAuthorization.php index e943a3f9..88f5d74c 100644 --- a/sample/payments/VoidAuthorization.php +++ b/sample/payments/VoidAuthorization.php @@ -4,10 +4,10 @@ // void an authorized payment. // API used: /v1/payments/authorization/<{authorizationid}>/void" -/** @var Authorization $authorization */ -$authorization = require 'AuthorizePayment.php'; -// Replace $authorizationid with any static Id you might already have. It will do a void on it -$authorizationId = '1BF65516U6866543H'; // $authorization->getId(); + +// Replace $authorizationId with any static Id you might already have. +$authorizationId = ""; + use PayPal\Api\Authorization; // ### VoidAuthorization