forked from laniatech/Checkout-NET-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunAllCaptureIntentFlow.cs
68 lines (61 loc) · 3.35 KB
/
RunAllCaptureIntentFlow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Samples.CaptureIntentExamples;
using PayPalCheckoutSdk.Orders;
using PayPalCheckoutSdk.Payments;
namespace Samples
{
public class RunAll
{
//Rename to Main1 => Main
static void Main1(string []args){
Console.WriteLine("Running Capture Intent Flow..");
var createOrderResponse = Samples.CaptureIntentExamples.CreateOrderSample.CreateOrder(true).Result;
var createOrderResult = createOrderResponse.Result<Order>();
Console.WriteLine("Status: {0}", createOrderResult.Status);
Console.WriteLine("Order Id: {0}", createOrderResult.Id);
Console.WriteLine("Intent: {0}", createOrderResult.CheckoutPaymentIntent);
Console.WriteLine("Links:");
foreach (var link in createOrderResult.Links)
{
Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
}
AmountWithBreakdown amount = createOrderResult.PurchaseUnits[0].AmountWithBreakdown;
Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value);
Console.WriteLine("Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n");
Console.Read();
Console.WriteLine("Capturing the payment...");
var captureOrderResponse = CaptureOrderSample.CaptureOrder(createOrderResult.Id, true).Result;
var captureOrderResult = captureOrderResponse.Result<Order>();
var captureId= "";
Console.WriteLine("Status: {0}", captureOrderResult.Status);
Console.WriteLine("Order Id: {0}", captureOrderResult.Id);
Console.WriteLine("Intent: {0}", captureOrderResult.CheckoutPaymentIntent);
Console.WriteLine("Links:");
foreach (var link in captureOrderResult.Links)
{
Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
}
foreach (PurchaseUnit purchaseUnit in captureOrderResult.PurchaseUnits)
{
foreach (PayPalCheckoutSdk.Orders.Capture capture in purchaseUnit.Payments.Captures)
{
captureId = capture.Id;
}
}
AmountWithBreakdown captureAmount = captureOrderResult.PurchaseUnits[0].AmountWithBreakdown;
Console.WriteLine("Buyer:");
Console.WriteLine("\tEmail Address: {0}\n\tName: {1} {2}",
captureOrderResult.Payer.Email, captureOrderResult.Payer.Name.GivenName, captureOrderResult.Payer.Name.Surname);
Console.WriteLine("Refunding the Order....");
var refundOrderResponse = CapturesRefundSample.CapturesRefund(captureId, true).Result;
var refundOrderResult = refundOrderResponse.Result<PayPalCheckoutSdk.Payments.Refund>();
Console.WriteLine("Status: {0}", refundOrderResult.Status);
Console.WriteLine("Refund Id: {0}", refundOrderResult.Id);
Console.WriteLine("Links:");
foreach (var link in refundOrderResult.Links)
{
Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
}
}
}
}