diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index bbccc3fb..6b2f8402 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -49,7 +49,29 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "billing/CreateBillingAgreementWithCreditCard", "title": "CreateBillingAgreementWithCreditCard" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Billing Agreement with Credit Card as Payment Source", + "slug": "create-billing-agreement-with-credit-card-as-payment-source" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Agreement", + "slug": "create-agreement" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -403,8 +425,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "invoice-templates/GetAllInvoiceTemplates", "title": "GetAllInvoiceTemplates" }, - "depth": 2, - "outline": [] + "depth": 2 }, { "type": "file", "data": { @@ -422,29 +443,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "invoice-templates/GetInvoiceTemplate", "title": "GetInvoiceTemplate" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Retrieve Invoice Template Sample", - "slug": "retrieve-invoice-template-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Retrieve Invoice Template", - "slug": "retrieve-invoice-template" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -724,53 +723,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "invoice/UpdateInvoice", "title": "UpdateInvoice" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 1, - "title": "Update Invoice Sample", - "slug": "update-invoice-sample" - }, - "depth": 1, - "children": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Update Invoice", - "slug": "update-invoice" - }, - "depth": 3 - }, { - "type": "heading", - "data": { - "level": 3, - "title": "NOTE: These are the work-around added to the", - "slug": "note-these-are-the-work-around-added-to-the" - }, - "depth": 3 - }, { - "type": "heading", - "data": { - "level": 3, - "title": "Update Invoice", - "slug": "update-invoice" - }, - "depth": 3 - }, { - "type": "heading", - "data": { - "level": 3, - "title": "Retrieve Invoice", - "slug": "retrieve-invoice" - }, - "depth": 3 - } - ] - } - ] + "depth": 2 } ] }, { @@ -1024,7 +977,18 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "notifications/ValidateWebhookEvent", "title": "ValidateWebhookEvent" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Validate Webhook", + "slug": "validate-webhook" + }, + "depth": 1 + } + ] }, { "type": "file", "data": { @@ -1070,29 +1034,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "payment-experience/CreateWebProfile", "title": "CreateWebProfile" }, - "depth": 2, - "outline": [ - { - "type": "heading", - "data": { - "level": 3, - "title": "Create Web Profile", - "slug": "create-web-profile" - }, - "depth": 3, - "children": [ - { - "type": "heading", - "data": { - "level": 4, - "title": "Payment Web experience profile resource", - "slug": "payment-web-experience-profile-resource" - }, - "depth": 4 - } - ] - } - ] + "depth": 2 }, { "type": "file", "data": { @@ -1228,7 +1170,29 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "payments/AuthorizePayment", "title": "AuthorizePayment" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Authorize Payment", + "slug": "authorize-payment" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1282,7 +1246,93 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "payments/CreatePayment", "title": "CreatePayment" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "CreatePaymentSample", + "slug": "createpaymentsample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "PaymentCard", + "slug": "paymentcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Itemized information", + "slug": "itemized-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional payment details", + "slug": "additional-payment-details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1319,6 +1369,118 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "title": "CreatePaymentUsingSavedCard" }, "depth": 2 + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/scoffey/paypal/server_sdk/PayPal-PHP-SDK/sample/payments/CreateThirdPartyPayment.php", + "projectPath": "payments/CreateThirdPartyPayment.php", + "targetPath": "payments/CreateThirdPartyPayment", + "pageTitle": "payments/CreateThirdPartyPayment", + "title": "CreateThirdPartyPayment" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "CreatePaymentSample", + "slug": "createpaymentsample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "PaymentCard", + "slug": "paymentcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Itemized information", + "slug": "itemized-information" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Additional payment details", + "slug": "additional-payment-details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payee", + "slug": "payee" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Create Payment", + "slug": "create-payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1390,7 +1552,29 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "payments/GetPayment", "title": "GetPayment" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "GetPaymentSample", + "slug": "getpaymentsample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Retrieve payment", + "slug": "retrieve-payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1588,7 +1772,29 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "payments/RefundCapture", "title": "RefundCapture" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Refund Capture Sample", + "slug": "refund-capture-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Refund", + "slug": "refund" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -1770,7 +1976,45 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "sale/RefundSale", "title": "RefundSale" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Sale Refund Sample", + "slug": "sale-refund-sample" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Refund amount", + "slug": "refund-amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Refund object", + "slug": "refund-object" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Sale", + "slug": "sale" + }, + "depth": 3 + } + ] + } + ] } ] }, { diff --git a/sample/doc/notifications/ValidateWebhookEvent.html b/sample/doc/notifications/ValidateWebhookEvent.html index 9cd58c29..1470979d 100644 --- a/sample/doc/notifications/ValidateWebhookEvent.html +++ b/sample/doc/notifications/ValidateWebhookEvent.html @@ -11,15 +11,46 @@ */ /** @var String $requestBody */ $requestBody = '{"id":"WH-9UG43882HX7271132-6E0871324L7949614","event_version":"1.0","create_time":"2016-09-21T22:00:45Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 21.0 USD","resource":{"id":"80F85758S3080410K","state":"completed","amount":{"total":"21.00","currency":"USD","details":{"subtotal":"17.50","tax":"1.30","shipping":"2.20"}},"payment_mode":"INSTANT_TRANSFER","protection_eligibility":"ELIGIBLE","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","transaction_fee":{"value":"0.91","currency":"USD"},"invoice_number":"57e3028db8d1b","custom":"","parent_payment":"PAY-7F371669SL612941HK7RQFDQ","create_time":"2016-09-21T21:59:02Z","update_time":"2016-09-21T22:00:06Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/80F85758S3080410K","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/80F85758S3080410K/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-7F371669SL612941HK7RQFDQ","rel":"parent_payment","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9UG43882HX7271132-6E0871324L7949614","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9UG43882HX7271132-6E0871324L7949614/resend","rel":"resend","method":"POST"}]}'; +/** +* Receive the entire body that you received from PayPal webhook. +* Just uncomment the below line to read the data from actual request. +*/ +/** @var String $bodyReceived */

$bodyReceived = file_get_contents('php://input');

+ $headers = array ( + 'Client-Pid' => '14910', + 'Cal-Poolstack' => 'amqunphttpdeliveryd:UNPHTTPDELIVERY*CalThreadId=0*TopLevelTxnStartTime=1579e71daf8*Host=slcsbamqunphttpdeliveryd3001', + 'Correlation-Id' => '958be65120106', + 'Host' => 'shiparound-dev.de', + 'User-Agent' => 'PayPal/AUHD-208.0-25552773', + 'Paypal-Auth-Algo' => 'SHA256withRSA', + 'Paypal-Cert-Url' => 'https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77', + 'Paypal-Auth-Version' => 'v2', + 'Paypal-Transmission-Sig' => 'eDOnWUj9FXOnr2naQnrdL7bhgejVSTwRbwbJ0kuk5wAtm2ZYkr7w5BSUDO7e5ZOsqLwN3sPn3RV85Jd9pjHuTlpuXDLYk+l5qiViPbaaC0tLV+8C/zbDjg2WCfvtf2NmFT8CHgPPQAByUqiiTY+RJZPPQC5np7j7WuxcegsJLeWStRAofsDLiSKrzYV3CKZYtNoNnRvYmSFMkYp/5vk4xGcQLeYNV1CC2PyqraZj8HGG6Y+KV4trhreV9VZDn+rPtLDZTbzUohie1LpEy31k2dg+1szpWaGYOz+MRb40U04oD7fD69vghCrDTYs5AsuFM2+WZtsMDmYGI0pxLjn2yw==', + 'Paypal-Transmission-Time' => '2016-09-21T22:00:46Z', + 'Paypal-Transmission-Id' => 'd938e770-8046-11e6-8103-6b62a8a99ac4', + 'Accept' => '*/*', +); -$signatureVerification = new VerifyWebhookSignature(); -$signatureVerification->setAuthAlgo("SHA256withRSA"); -$signatureVerification->setTransmissionId("d938e770-8046-11e6-8103-6b62a8a99ac4"); -$signatureVerification->setCertUrl("https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77"); // todo: this isn't going to work -$signatureVerification->setWebhookId("9XL90610J3647323C"); -$signatureVerification->setTransmissionSig("eDOnWUj9FXOnr2naQnrdL7bhgejVSTwRbwbJ0kuk5wAtm2ZYkr7w5BSUDO7e5ZOsqLwN3sPn3RV85Jd9pjHuTlpuXDLYk+l5qiViPbaaC0tLV+8C/zbDjg2WCfvtf2NmFT8CHgPPQAByUqiiTY+RJZPPQC5np7j7WuxcegsJLeWStRAofsDLiSKrzYV3CKZYtNoNnRvYmSFMkYp/5vk4xGcQLeYNV1CC2PyqraZj8HGG6Y+KV4trhreV9VZDn+rPtLDZTbzUohie1LpEy31k2dg+1szpWaGYOz+MRb40U04oD7fD69vghCrDTYs5AsuFM2+WZtsMDmYGI0pxLjn2yw=="); -$signatureVerification->setTransmissionTime("2016-09-21T22:00:46Z"); +/** +* Receive HTTP headers that you received from PayPal webhook. +* Just uncomment the below line to read the data from actual request. +*/ +/** @var Array $headers */ +//$headers = getallheaders(); +/** +* In Documentions https://developer.paypal.com/docs/api/webhooks/#verify-webhook-signature_post +* All header keys as UPPERCASE, but I recive the header key as the example array, First letter as UPPERCASE +*/ +$headers = array_change_key_case($headers, CASE_UPPER); + +$signatureVerification = new VerifyWebhookSignature(); +$signatureVerification->setAuthAlgo($headers['PAYPAL-AUTH-ALGO']); +$signatureVerification->setTransmissionId($headers['PAYPAL-TRANSMISSION-ID']); +$signatureVerification->setCertUrl($headers['PAYPAL-CERT-URL']); +$signatureVerification->setWebhookId("9XL90610J3647323C"); // Note that the Webhook ID must be a currently valid Webhook that you created with your client ID/secret. +$signatureVerification->setTransmissionSig($headers['PAYPAL-TRANSMISSION-SIG']); +$signatureVerification->setTransmissionTime($headers['PAYPAL-TRANSMISSION-TIME']); $webhookEvent = new WebhookEvent(); $webhookEvent->fromJson($requestBody); diff --git a/sample/doc/payments/CreatePayment.html b/sample/doc/payments/CreatePayment.html index 1ba9d669..07208e1e 100644 --- a/sample/doc/payments/CreatePayment.html +++ b/sample/doc/payments/CreatePayment.html @@ -21,8 +21,8 @@ ->setExpireYear("2019") ->setCvv2("012") ->setFirstName("Joe") - ->setLastName("Shopper") - ->setBillingCountry("US");

FundingInstrument

+ ->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(); diff --git a/sample/doc/payments/CreateThirdPartyPayment.html b/sample/doc/payments/CreateThirdPartyPayment.html new file mode 100644 index 00000000..33de3917 --- /dev/null +++ b/sample/doc/payments/CreateThirdPartyPayment.html @@ -0,0 +1,90 @@ +payments/CreateThirdPartyPayment
payments/CreateThirdPartyPayment.php
<?php

CreatePaymentSample

+

This sample code demonstrate how you can process +a direct credit card payment. Please note that direct +credit card payment and related features using the +REST API is restricted in some countries. +API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Item; +use PayPal\Api\ItemList; +use PayPal\Api\Payee; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\PaymentCard; +use PayPal\Api\Transaction;

PaymentCard

+

A resource representing a payment card that can be +used to fund a payment.

$card = new PaymentCard(); +$card->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);

Payee

+

Specify a payee with that user's email or merchant id +Merchant Id can be found at https://www.paypal.com/businessprofile/settings/

$payee = new Payee(); +$payee->setEmail("stevendcoffey-facilitator@gmail.com");

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") + ->setPayee($payee) + ->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 <a href="https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1413">Step 4, on this link</a>, 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/doc/payments/RefundCapture.html b/sample/doc/payments/RefundCapture.html index 0bb8a317..546dd9c8 100644 --- a/sample/doc/payments/RefundCapture.html +++ b/sample/doc/payments/RefundCapture.html @@ -5,15 +5,16 @@ $capture = require 'AuthorizationCapture.php'; use PayPal\Api\Capture; -use PayPal\Api\Refund;

Refund

+use PayPal\Api\Refund; +use PayPal\Api\RefundRequest;

Refund

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

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

$refundRequest = new RefundRequest(); +$refundRequest->setAmount($amt); try {

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

$apiContext = getApiContext($clientId, $clientSecret); - $captureRefund = $capture->refund($refund, $apiContext); -} catch (Exception $ex) {

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

ResultPrinter::printError("Refund Capture", "Capture", null, $refund, $ex); + $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(), $refund, $captureRefund);
+}

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

ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refundRequest, $captureRefund);
diff --git a/sample/doc/sale/RefundSale.html b/sample/doc/sale/RefundSale.html index fa21d155..2022484c 100644 --- a/sample/doc/sale/RefundSale.html +++ b/sample/doc/sale/RefundSale.html @@ -8,22 +8,23 @@ use PayPal\Api\Amount; use PayPal\Api\Refund; +use PayPal\Api\RefundRequest; use PayPal\Api\Sale;

Refund amount

Includes both the refunded amount (to Payer) and refunded fee (to Payee). Use the $amt->details field to mention fees refund details.

$amt = new Amount(); $amt->setCurrency('USD') - ->setTotal(0.01);

Refund object

$refund = new Refund(); -$refund->setAmount($amt);

Sale

+ ->setTotal(0.01);

Refund object

$refundRequest = new RefundRequest(); +$refundRequest->setAmount($amt);

Sale

A sale transaction. Create a Sale object with the given sale transaction id.

$sale = new Sale(); $sale->setId($saleId); try {

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

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

Refund the sale -(See bootstrap.php for more on ApiContext)

$refundedSale = $sale->refund($refund, $apiContext); -} catch (Exception $ex) {

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

ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex); +(See bootstrap.php for more on ApiContext)

$refundedSale = $sale->refundSale($refundRequest, $apiContext); +} catch (Exception $ex) {

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

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

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

ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale); +}

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

ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refundRequest, $refundedSale); return $refundedSale;
diff --git a/sample/index.php b/sample/index.php index cfc38369..974f99eb 100644 --- a/sample/index.php +++ b/sample/index.php @@ -303,6 +303,17 @@ class="fa fa-file-code-o"> +
  • +
    +
    Payments to a 3rd-Party Payee
    + +
    +
  • Payments using saved credit card (using Vault APIs)
    diff --git a/sample/payments/CreateThirdPartyPayment.php b/sample/payments/CreateThirdPartyPayment.php new file mode 100644 index 00000000..e90a9e64 --- /dev/null +++ b/sample/payments/CreateThirdPartyPayment.php @@ -0,0 +1,133 @@ +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); + +// ### Payee +// Specify a payee with that user's email or merchant id +// Merchant Id can be found at https://www.paypal.com/businessprofile/settings/ +$payee = new Payee(); +$payee->setEmail("stevendcoffey-facilitator@gmail.com"); + +// ### 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") + ->setPayee($payee) + ->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/RefundCapture.php b/sample/payments/RefundCapture.php index 9fbc5eb4..8d47777f 100644 --- a/sample/payments/RefundCapture.php +++ b/sample/payments/RefundCapture.php @@ -8,25 +8,26 @@ 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 -$refund = new Refund(); -$refund->setAmount($amt); +$refundRequest = new RefundRequest(); +$refundRequest->setAmount($amt); try { // Create a new apiContext object so we send a new // PayPal-Request-Id (idempotency) header for this resource $apiContext = getApiContext($clientId, $clientSecret); - $captureRefund = $capture->refund($refund, $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, $refund, $ex); + 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(), $refund, $captureRefund); +ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refundRequest, $captureRefund); diff --git a/sample/sale/RefundSale.php b/sample/sale/RefundSale.php index ccf3b278..bf61ab0d 100644 --- a/sample/sale/RefundSale.php +++ b/sample/sale/RefundSale.php @@ -12,6 +12,7 @@ use PayPal\Api\Amount; use PayPal\Api\Refund; +use PayPal\Api\RefundRequest; use PayPal\Api\Sale; // ### Refund amount @@ -23,8 +24,8 @@ ->setTotal(0.01); // ### Refund object -$refund = new Refund(); -$refund->setAmount($amt); +$refundRequest = new RefundRequest(); +$refundRequest->setAmount($amt); // ###Sale // A sale transaction. @@ -39,14 +40,14 @@ // Refund the sale // (See bootstrap.php for more on `ApiContext`) - $refundedSale = $sale->refund($refund, $apiContext); + $refundedSale = $sale->refundSale($refundRequest, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex); + ResultPrinter::printError("Refund Sale", "Sale", null, $refundRequest, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale); +ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refundRequest, $refundedSale); return $refundedSale;