/
DwollaTransactionService.cs
142 lines (108 loc) · 4.88 KB
/
DwollaTransactionService.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using Dwolla.Helpers;
using Dwolla.Models;
using RestSharp;
namespace Dwolla.Services
{
public class DwollaTransactionService : DwollaService
{
public DwollaTransactionService(bool sandbox = false)
: base(sandbox)
{ }
public DwollaResponse<string> SendFunds(SendTransactionOptions options)
{
var resource = Urls.Transactions(Sandbox) + "/send";
//var client = new RestClient(Urls.BaseUrl(Sandbox));
var data = new {
oauth_token = options.OAuthToken,
pin = options.Pin,
destinationId = options.DestinationId,
amount = options.Amount,
assumeCosts = options.AssumeCosts,
destinationType = options.DestinationType,
facilitatorAmount = options.FacilitatorAmount,
fundsSource = options.FundsSource,
notes = options.Notes,
assumeAdditionalFees = options.AssumeAdditionalFees
};
var request = new RestRequest(resource, Method.POST) {
RequestFormat = DataFormat.Json
};
request.AddBody(data);
var response = Client.Execute(request);
return Mapper<DwollaResponse<string>>.MapFromJson(response.Content);
}
public DwollaResponse<IList<DwollaTransaction>> GetByUser(ListTransactionOptions options)
{
var parameters = new Dictionary<string, object>()
{
{"oauth_token", options.OAuthToken},
{"sinceDate", options.SinceDate},
{"types", options.Types},
{"limit", options.Limit},
{"skip", options.Limit}
};
string encodedUrl = HttpHelper.BuildUrl(Urls.Transactions(Sandbox, true), parameters);
var rawResponse = Requestor.GetString(encodedUrl);
return Mapper<DwollaResponse<IList<DwollaTransaction>>>.MapFromJson(rawResponse);
}
public DwollaResponse<DwollaTransactionStats> GetTransactionStats(TransactionStatsOptions options)
{
var resource = Urls.Transactions(Sandbox) + "/stats";
var parameters = new Dictionary<string, object>()
{
{"oauth_token", options.OAuthToken},
{"types", options.StatTypes},
{"startDate", options.StartDate},
{"endDate", options.EndDate}
};
string encodedUrl = HttpHelper.BuildUrl(resource, parameters);
var rawResponse = Requestor.GetString(encodedUrl);
return Mapper<DwollaResponse<DwollaTransactionStats>>.MapFromJson(rawResponse);
}
public DwollaResponse<DwollaRefund> Refund(RefundOptions options)
{
var url = Urls.Transactions(Sandbox) + "/refund";
//var client = new RestClient(Urls.BaseUrl());
var data = new
{
oauth_token = options.OAuthToken,
pin = options.Pin,
amount = options.Amount,
fundsSource = options.FundsSource,
notes = options.Notes,
transactionId = options.TransactionId
};
var request = new RestRequest(url, Method.POST)
{
RequestFormat = DataFormat.Json
};
request.AddBody(data);
var response = Client.Execute(request);
return Mapper<DwollaResponse<DwollaRefund>>.MapFromJson(response.Content);
}
public DwollaResponse<DwollaTransaction> GetById(string transactionId, string oAuthToken)
{
var parameters = new Dictionary<string, object> { { "oauth_token", oAuthToken } };
var endpoint = string.Format("{0}/{1}", Urls.Transactions(Sandbox, true), transactionId);
string encodedUrl = HttpHelper.BuildUrl(endpoint, parameters);
string rawResponse = Requestor.GetString(encodedUrl);
return Mapper<DwollaResponse<DwollaTransaction>>.MapFromJson(rawResponse);
}
// Todo: not sure if this still works
public DwollaResponse<DwollaTransaction> GetById(
string transactionId, string appKey, string appSecret)
{
var parameters = new Dictionary<string, object>()
{
{"client_id", appKey},
{"client_secret", appSecret}
};
var endpoint = string.Format("{0}/{1}", Urls.Transactions(Sandbox, true), transactionId);
string encodedUrl = HttpHelper.BuildUrl(endpoint, parameters);
string rawResponse = Requestor.GetString(encodedUrl);
return Mapper<DwollaResponse<DwollaTransaction>>.MapFromJson(rawResponse);
}
}
}