Update samples for 3rd Party Payments

This commit is contained in:
jaypatel512 and sdcoffey
2016-10-27 14:02:22 -07:00
parent c2947ff409
commit cbff55238d
10 changed files with 645 additions and 132 deletions

View File

@@ -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", "pageTitle": "billing/CreateBillingAgreementWithCreditCard",
"title": "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", "type": "file",
"data": { "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", "pageTitle": "invoice-templates/GetAllInvoiceTemplates",
"title": "GetAllInvoiceTemplates" "title": "GetAllInvoiceTemplates"
}, },
"depth": 2, "depth": 2
"outline": []
}, { }, {
"type": "file", "type": "file",
"data": { "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", "pageTitle": "invoice-templates/GetInvoiceTemplate",
"title": "GetInvoiceTemplate" "title": "GetInvoiceTemplate"
}, },
"depth": 2, "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
}
]
}
]
}, { }, {
"type": "file", "type": "file",
"data": { "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", "pageTitle": "invoice/UpdateInvoice",
"title": "UpdateInvoice" "title": "UpdateInvoice"
}, },
"depth": 2, "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
}
]
}
]
} }
] ]
}, { }, {
@@ -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", "pageTitle": "notifications/ValidateWebhookEvent",
"title": "ValidateWebhookEvent" "title": "ValidateWebhookEvent"
}, },
"depth": 2 "depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Validate Webhook",
"slug": "validate-webhook"
},
"depth": 1
}
]
}, { }, {
"type": "file", "type": "file",
"data": { "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", "pageTitle": "payment-experience/CreateWebProfile",
"title": "CreateWebProfile" "title": "CreateWebProfile"
}, },
"depth": 2, "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
}
]
}
]
}, { }, {
"type": "file", "type": "file",
"data": { "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", "pageTitle": "payments/AuthorizePayment",
"title": "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", "type": "file",
"data": { "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", "pageTitle": "payments/CreatePayment",
"title": "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", "type": "file",
"data": { "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" "title": "CreatePaymentUsingSavedCard"
}, },
"depth": 2 "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", "type": "file",
"data": { "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", "pageTitle": "payments/GetPayment",
"title": "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", "type": "file",
"data": { "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", "pageTitle": "payments/RefundCapture",
"title": "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", "type": "file",
"data": { "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", "pageTitle": "sale/RefundSale",
"title": "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
}
]
}
]
} }
] ]
}, { }, {

View File

@@ -11,15 +11,46 @@ To resolve that, we need to use alternative, which makes a call to PayPal's
*/</span> */</span>
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> String $requestBody */</span> <span class="hljs-comment">/** <span class="hljs-doctag">@var</span> String $requestBody */</span>
<span class="hljs-variable">$requestBody</span> = <span class="hljs-string">'{"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"}]}'</span>; <span class="hljs-variable">$requestBody</span> = <span class="hljs-string">'{"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"}]}'</span>;
<span class="hljs-comment">/**
* Receive the entire body that you received from PayPal webhook.
* Just uncomment the below line to read the data from actual request.
*/</span>
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> String $bodyReceived */</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>$bodyReceived = file_get_contents(&#39;php://input&#39;);</p></div></div><div class="code"><div class="wrapper">
<span class="hljs-variable">$headers</span> = <span class="hljs-keyword">array</span> (
<span class="hljs-string">'Client-Pid'</span> =&gt; <span class="hljs-string">'14910'</span>,
<span class="hljs-string">'Cal-Poolstack'</span> =&gt; <span class="hljs-string">'amqunphttpdeliveryd:UNPHTTPDELIVERY*CalThreadId=0*TopLevelTxnStartTime=1579e71daf8*Host=slcsbamqunphttpdeliveryd3001'</span>,
<span class="hljs-string">'Correlation-Id'</span> =&gt; <span class="hljs-string">'958be65120106'</span>,
<span class="hljs-string">'Host'</span> =&gt; <span class="hljs-string">'shiparound-dev.de'</span>,
<span class="hljs-string">'User-Agent'</span> =&gt; <span class="hljs-string">'PayPal/AUHD-208.0-25552773'</span>,
<span class="hljs-string">'Paypal-Auth-Algo'</span> =&gt; <span class="hljs-string">'SHA256withRSA'</span>,
<span class="hljs-string">'Paypal-Cert-Url'</span> =&gt; <span class="hljs-string">'https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77'</span>,
<span class="hljs-string">'Paypal-Auth-Version'</span> =&gt; <span class="hljs-string">'v2'</span>,
<span class="hljs-string">'Paypal-Transmission-Sig'</span> =&gt; <span class="hljs-string">'eDOnWUj9FXOnr2naQnrdL7bhgejVSTwRbwbJ0kuk5wAtm2ZYkr7w5BSUDO7e5ZOsqLwN3sPn3RV85Jd9pjHuTlpuXDLYk+l5qiViPbaaC0tLV+8C/zbDjg2WCfvtf2NmFT8CHgPPQAByUqiiTY+RJZPPQC5np7j7WuxcegsJLeWStRAofsDLiSKrzYV3CKZYtNoNnRvYmSFMkYp/5vk4xGcQLeYNV1CC2PyqraZj8HGG6Y+KV4trhreV9VZDn+rPtLDZTbzUohie1LpEy31k2dg+1szpWaGYOz+MRb40U04oD7fD69vghCrDTYs5AsuFM2+WZtsMDmYGI0pxLjn2yw=='</span>,
<span class="hljs-string">'Paypal-Transmission-Time'</span> =&gt; <span class="hljs-string">'2016-09-21T22:00:46Z'</span>,
<span class="hljs-string">'Paypal-Transmission-Id'</span> =&gt; <span class="hljs-string">'d938e770-8046-11e6-8103-6b62a8a99ac4'</span>,
<span class="hljs-string">'Accept'</span> =&gt; <span class="hljs-string">'*/*'</span>,
);
<span class="hljs-comment">/**
* Receive HTTP headers that you received from PayPal webhook.
* Just uncomment the below line to read the data from actual request.
*/</span>
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Array $headers */</span>
<span class="hljs-comment">//$headers = getallheaders();</span>
<span class="hljs-comment">/**
* 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
*/</span>
<span class="hljs-variable">$headers</span> = array_change_key_case(<span class="hljs-variable">$headers</span>, CASE_UPPER);
<span class="hljs-variable">$signatureVerification</span> = <span class="hljs-keyword">new</span> VerifyWebhookSignature(); <span class="hljs-variable">$signatureVerification</span> = <span class="hljs-keyword">new</span> VerifyWebhookSignature();
<span class="hljs-variable">$signatureVerification</span>-&gt;setAuthAlgo(<span class="hljs-string">"SHA256withRSA"</span>); <span class="hljs-variable">$signatureVerification</span>-&gt;setAuthAlgo(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-AUTH-ALGO'</span>]);
<span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionId(<span class="hljs-string">"d938e770-8046-11e6-8103-6b62a8a99ac4"</span>); <span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionId(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-TRANSMISSION-ID'</span>]);
<span class="hljs-variable">$signatureVerification</span>-&gt;setCertUrl(<span class="hljs-string">"https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77"</span>); <span class="hljs-comment">// <span class="hljs-doctag">todo:</span> this isn't going to work</span> <span class="hljs-variable">$signatureVerification</span>-&gt;setCertUrl(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-CERT-URL'</span>]);
<span class="hljs-variable">$signatureVerification</span>-&gt;setWebhookId(<span class="hljs-string">"9XL90610J3647323C"</span>); <span class="hljs-variable">$signatureVerification</span>-&gt;setWebhookId(<span class="hljs-string">"9XL90610J3647323C"</span>); <span class="hljs-comment">// Note that the Webhook ID must be a currently valid Webhook that you created with your client ID/secret.</span>
<span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionSig(<span class="hljs-string">"eDOnWUj9FXOnr2naQnrdL7bhgejVSTwRbwbJ0kuk5wAtm2ZYkr7w5BSUDO7e5ZOsqLwN3sPn3RV85Jd9pjHuTlpuXDLYk+l5qiViPbaaC0tLV+8C/zbDjg2WCfvtf2NmFT8CHgPPQAByUqiiTY+RJZPPQC5np7j7WuxcegsJLeWStRAofsDLiSKrzYV3CKZYtNoNnRvYmSFMkYp/5vk4xGcQLeYNV1CC2PyqraZj8HGG6Y+KV4trhreV9VZDn+rPtLDZTbzUohie1LpEy31k2dg+1szpWaGYOz+MRb40U04oD7fD69vghCrDTYs5AsuFM2+WZtsMDmYGI0pxLjn2yw=="</span>); <span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionSig(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-TRANSMISSION-SIG'</span>]);
<span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionTime(<span class="hljs-string">"2016-09-21T22:00:46Z"</span>); <span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionTime(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-TRANSMISSION-TIME'</span>]);
<span class="hljs-variable">$webhookEvent</span> = <span class="hljs-keyword">new</span> WebhookEvent(); <span class="hljs-variable">$webhookEvent</span> = <span class="hljs-keyword">new</span> WebhookEvent();
<span class="hljs-variable">$webhookEvent</span>-&gt;fromJson(<span class="hljs-variable">$requestBody</span>); <span class="hljs-variable">$webhookEvent</span>-&gt;fromJson(<span class="hljs-variable">$requestBody</span>);

View File

@@ -21,8 +21,8 @@ used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><s
-&gt;setExpireYear(<span class="hljs-string">"2019"</span>) -&gt;setExpireYear(<span class="hljs-string">"2019"</span>)
-&gt;setCvv2(<span class="hljs-string">"012"</span>) -&gt;setCvv2(<span class="hljs-string">"012"</span>)
-&gt;setFirstName(<span class="hljs-string">"Joe"</span>) -&gt;setFirstName(<span class="hljs-string">"Joe"</span>)
-&gt;setLastName(<span class="hljs-string">"Shopper"</span>) -&gt;setBillingCountry(<span class="hljs-string">"US"</span>)
-&gt;setBillingCountry(<span class="hljs-string">"US"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3> -&gt;setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
<p>A resource representing a Payer&#39;s funding instrument. <p>A resource representing a Payer&#39;s funding instrument.
For direct credit card payments, set the CreditCard For direct credit card payments, set the CreditCard
field on this object.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument(); field on this object.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument();

View File

@@ -0,0 +1,90 @@
<!DOCTYPE html><html lang="en"><head><title>payments/CreateThirdPartyPayment</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="payments/CreateThirdPartyPayment"><meta name="groc-project-path" content="payments/CreateThirdPartyPayment.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">payments/CreateThirdPartyPayment.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="createpaymentsample">CreatePaymentSample</h1>
<p>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</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FundingInstrument</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ItemList</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payee</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentCard</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="paymentcard">PaymentCard</h3>
<p>A resource representing a payment card that can be
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> PaymentCard();
<span class="hljs-variable">$card</span>-&gt;setType(<span class="hljs-string">"visa"</span>)
-&gt;setNumber(<span class="hljs-string">"4669424246660779"</span>)
-&gt;setExpireMonth(<span class="hljs-string">"11"</span>)
-&gt;setExpireYear(<span class="hljs-string">"2019"</span>)
-&gt;setCvv2(<span class="hljs-string">"012"</span>)
-&gt;setFirstName(<span class="hljs-string">"Joe"</span>)
-&gt;setBillingCountry(<span class="hljs-string">"US"</span>)
-&gt;setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
<p>A resource representing a Payer&#39;s funding instrument.
For direct credit card payments, set the CreditCard
field on this object.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument();
<span class="hljs-variable">$fi</span>-&gt;setPaymentCard(<span class="hljs-variable">$card</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payer">Payer</h3>
<p>A resource representing a Payer that funds a payment
For direct credit card payments, set payment method
to &#39;credit_card&#39; and add an array of funding instruments.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
-&gt;setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="itemized-information">Itemized information</h3>
<p>(Optional) Lets you specify item wise
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item1</span>-&gt;setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
-&gt;setDescription(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">1</span>)
-&gt;setTax(<span class="hljs-number">0.3</span>)
-&gt;setPrice(<span class="hljs-number">7.50</span>);
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item2</span>-&gt;setName(<span class="hljs-string">'Granola bars'</span>)
-&gt;setDescription(<span class="hljs-string">'Granola Bars with Peanuts'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">5</span>)
-&gt;setTax(<span class="hljs-number">0.2</span>)
-&gt;setPrice(<span class="hljs-number">2</span>);
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
<span class="hljs-variable">$itemList</span>-&gt;setItems(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$item1</span>, <span class="hljs-variable">$item2</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-payment-details">Additional payment details</h3>
<p>Use this optional field to set additional
payment information such as tax, shipping
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
<span class="hljs-variable">$details</span>-&gt;setShipping(<span class="hljs-number">1.2</span>)
-&gt;setTax(<span class="hljs-number">1.3</span>)
-&gt;setSubtotal(<span class="hljs-number">17.5</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Lets you specify a payment amount.
You can also specify additional details
such as shipping, tax.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
-&gt;setTotal(<span class="hljs-number">20</span>)
-&gt;setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payee">Payee</h3>
<p>Specify a payee with that user&#39;s email or merchant id
Merchant Id can be found at <a href="https://www.paypal.com/businessprofile/settings/">https://www.paypal.com/businessprofile/settings/</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payee</span> = <span class="hljs-keyword">new</span> Payee();
<span class="hljs-variable">$payee</span>-&gt;setEmail(<span class="hljs-string">"stevendcoffey-facilitator@gmail.com"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a
payment - what is the payment for and who
is fulfilling it. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
<span class="hljs-variable">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>)
-&gt;setItemList(<span class="hljs-variable">$itemList</span>)
-&gt;setDescription(<span class="hljs-string">"Payment description"</span>)
-&gt;setPayee(<span class="hljs-variable">$payee</span>)
-&gt;setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using
the above types and intent set to sale &#39;sale&#39;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"sale"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by calling the payment-&gt;create() method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
The return object contains the state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$payment</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">'Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using &lt;a href="https://www.paypal-knowledge.com/infocenter/index?page=content&amp;widgetview=true&amp;id=FAQ1413"&gt;Step 4, on this link&lt;/a&gt;, and using it.'</span>, <span class="hljs-string">'Payment'</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">'Create Payment Using Credit Card'</span>, <span class="hljs-string">'Payment'</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>

View File

@@ -5,15 +5,16 @@ API used: /v1/payments/capture/{<captureID>}/refund</p></div></div><div class="c
<span class="hljs-variable">$capture</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizationCapture.php'</span>; <span class="hljs-variable">$capture</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizationCapture.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3> <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RefundRequest</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3>
<p>Create a refund object indicating <p>Create a refund object indicating
refund amount and call the refund method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund(); refund amount and call the refund method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$refundRequest</span> = <span class="hljs-keyword">new</span> RefundRequest();
<span class="hljs-variable">$refund</span>-&gt;setAmount(<span class="hljs-variable">$amt</span>); <span class="hljs-variable">$refundRequest</span>-&gt;setAmount(<span class="hljs-variable">$amt</span>);
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new <span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>); PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>);
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>-&gt;refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>); <span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>-&gt;refundCapturedPayment(<span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$ex</span>); } <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>); <span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$captureRefund</span>-&gt;getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$captureRefund</span>);</div></div></div></div></body></html> }</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper">ResultPrinter::printResult(<span class="hljs-string">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$captureRefund</span>-&gt;getId(), <span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$captureRefund</span>);</div></div></div></div></body></html>

View File

@@ -8,22 +8,23 @@ API used: /v1/payments/sale/{sale-id}/refund</p></div></div><div class="code"><d
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RefundRequest</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Sale</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-amount">Refund amount</h3> <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Sale</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-amount">Refund amount</h3>
<p>Includes both the refunded amount (to Payer) <p>Includes both the refunded amount (to Payer)
and refunded fee (to Payee). Use the $amt-&gt;details and refunded fee (to Payee). Use the $amt-&gt;details
field to mention fees refund details.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount(); field to mention fees refund details.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amt</span>-&gt;setCurrency(<span class="hljs-string">'USD'</span>) <span class="hljs-variable">$amt</span>-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setTotal(<span class="hljs-number">0.01</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-object">Refund object</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund(); -&gt;setTotal(<span class="hljs-number">0.01</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-object">Refund object</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-variable">$refundRequest</span> = <span class="hljs-keyword">new</span> RefundRequest();
<span class="hljs-variable">$refund</span>-&gt;setAmount(<span class="hljs-variable">$amt</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="sale">Sale</h3> <span class="hljs-variable">$refundRequest</span>-&gt;setAmount(<span class="hljs-variable">$amt</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="sale">Sale</h3>
<p>A sale transaction. <p>A sale transaction.
Create a Sale object with the Create a Sale object with the
given sale transaction id.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$sale</span> = <span class="hljs-keyword">new</span> Sale(); given sale transaction id.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$sale</span> = <span class="hljs-keyword">new</span> Sale();
<span class="hljs-variable">$sale</span>-&gt;setId(<span class="hljs-variable">$saleId</span>); <span class="hljs-variable">$sale</span>-&gt;setId(<span class="hljs-variable">$saleId</span>);
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new <span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Refund the sale PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Refund the sale
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$refundedSale</span> = <span class="hljs-variable">$sale</span>-&gt;refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>); (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$refundedSale</span> = <span class="hljs-variable">$sale</span>-&gt;refundSale(<span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Refund Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$refundedSale</span>-&gt;getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$ex</span>); } <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Refund Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>); <span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Refund Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$refundedSale</span>-&gt;getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$refundedSale</span>); }</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper">ResultPrinter::printResult(<span class="hljs-string">"Refund Sale"</span>, <span class="hljs-string">"Sale"</span>, <span class="hljs-variable">$refundedSale</span>-&gt;getId(), <span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$refundedSale</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$refundedSale</span>;</div></div></div></div></body></html> <span class="hljs-keyword">return</span> <span class="hljs-variable">$refundedSale</span>;</div></div></div></div></body></html>

View File

@@ -303,6 +303,17 @@ if (PHP_SAPI == 'cli') {
</div> </div>
</div> </div>
</li> </li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Payments to a 3rd-Party Payee</h5></div>
<div class="col-md-4">
<a href="payments/CreateThirdPartyPayment.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/CreateThirdPartyPayment.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item"> <li class="list-group-item">
<div class="row"> <div class="row">
<div class="col-md-8"><h5>Payments using saved credit card <small>(using Vault APIs)</small></h5></div> <div class="col-md-8"><h5>Payments using saved credit card <small>(using Vault APIs)</small></h5></div>

View File

@@ -0,0 +1,133 @@
<?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;

View File

@@ -8,25 +8,26 @@ $capture = require 'AuthorizationCapture.php';
use PayPal\Api\Capture; use PayPal\Api\Capture;
use PayPal\Api\Refund; use PayPal\Api\Refund;
use PayPal\Api\RefundRequest;
// ### Refund // ### Refund
// Create a refund object indicating // Create a refund object indicating
// refund amount and call the refund method // refund amount and call the refund method
$refund = new Refund(); $refundRequest = new RefundRequest();
$refund->setAmount($amt); $refundRequest->setAmount($amt);
try { try {
// Create a new apiContext object so we send a new // Create a new apiContext object so we send a new
// PayPal-Request-Id (idempotency) header for this resource // PayPal-Request-Id (idempotency) header for this resource
$apiContext = getApiContext($clientId, $clientSecret); $apiContext = getApiContext($clientId, $clientSecret);
$captureRefund = $capture->refund($refund, $apiContext); $captureRefund = $capture->refundCapturedPayment($refundRequest, $apiContext);
} catch (Exception $ex) { } catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY // 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); exit(1);
} }
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY // 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);

View File

@@ -12,6 +12,7 @@ $saleId = $sale->getId();
use PayPal\Api\Amount; use PayPal\Api\Amount;
use PayPal\Api\Refund; use PayPal\Api\Refund;
use PayPal\Api\RefundRequest;
use PayPal\Api\Sale; use PayPal\Api\Sale;
// ### Refund amount // ### Refund amount
@@ -23,8 +24,8 @@ $amt->setCurrency('USD')
->setTotal(0.01); ->setTotal(0.01);
// ### Refund object // ### Refund object
$refund = new Refund(); $refundRequest = new RefundRequest();
$refund->setAmount($amt); $refundRequest->setAmount($amt);
// ###Sale // ###Sale
// A sale transaction. // A sale transaction.
@@ -39,14 +40,14 @@ try {
// Refund the sale // Refund the sale
// (See bootstrap.php for more on `ApiContext`) // (See bootstrap.php for more on `ApiContext`)
$refundedSale = $sale->refund($refund, $apiContext); $refundedSale = $sale->refundSale($refundRequest, $apiContext);
} catch (Exception $ex) { } catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY // 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); exit(1);
} }
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY // 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; return $refundedSale;