forked from laniatech/Checkout-NET-SDK
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCapturesRefundSample.cs
63 lines (57 loc) · 1.96 KB
/
CapturesRefundSample.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
using PayPal.Sdk.Checkout.Authentication;
using PayPal.Sdk.Checkout.ContractEnums;
using PayPal.Sdk.Checkout.Core.Interfaces;
using PayPal.Sdk.Checkout.Extensions;
using PayPal.Sdk.Checkout.Payments;
using System;
using System.Threading.Tasks;
namespace PayPal.Sdk.Checkout.Samples;
public static class CapturesRefundSample
{
/// <summary>
/// Method for refund the capture. Valid capture Id should be passed an argument to this method.
/// </summary>
public static async Task<PaymentRefund?> CapturesRefund(
this IPayPalHttpClient httpClient, AccessToken accessToken,
string captureId, bool debug = false
)
{
var response = await httpClient.CapturesRefundAsync(
accessToken,
captureId,
request =>
{
request.SetPreferReturn(EPreferReturn.Representation);
request.SetRequestBody(new RefundRequest
{
Amount = new PaymentMoney
{
Value = "20.00",
CurrencyCode = "USD",
},
});
}
).ConfigureAwait(false);
if (debug && response != null)
{
Console.WriteLine("Status: {0}", response.Status);
Console.WriteLine("Refund Id: {0}", response.Id);
Console.WriteLine("Links:");
foreach (var link in response.Links)
{
Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
}
Console.WriteLine("Response JSON: \n {0}", response.AsJson());
}
return response;
}
/*
Driver Function to perform refund on capture.
Capture Id should be replaced with the valid capture id.
*/
// static void Main(string[] args)
// {
// string CaptureId = "<<REPLACE-WITH-VALID-CAPTURE-ID>>";
// CapturesRefund(CaptureId, true).Wait();
// }
}