Skip to content
This repository was archived by the owner on Oct 9, 2024. It is now read-only.

Commit 12e4669

Browse files
Added Refund::Transaction
Added Refund::Transaction API Made parseformats static in JSON Converters (thanks, Damiaan)
1 parent 87bcdfc commit 12e4669

File tree

11 files changed

+512
-24
lines changed

11 files changed

+512
-24
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using PAYNLSDK.API.Refund.Transaction;
3+
using PAYNLSDK;
4+
using PAYNLSDK.Enums;
5+
6+
namespace PAYNLFormsApp.Fixtures
7+
{
8+
public class RefundTransaction
9+
{
10+
static public Request GetFixture()
11+
{
12+
Request request = GetFixtureNoProductLines();
13+
request.AddProduct("SKU-8489", 1);
14+
request.AddProduct("SKU-8421", 2);
15+
request.AddProduct("SKU-2359", 3);
16+
17+
return request;
18+
}
19+
20+
static public Request GetFixtureNoProductLines()
21+
{
22+
Request request = new Request("abcedef");
23+
request.Amount = 6489;
24+
request.Description = "Transaction refund test description";
25+
request.ProcessDate = new DateTime(2018, 07, 15, 0, 0, 0, DateTimeKind.Local);
26+
request.ExchangeUrl = "https://www.example.com/callbacktransactionrefund";
27+
28+
return request;
29+
}
30+
31+
}
32+
}

PAYNLFormsApp/Form1.Designer.cs

Lines changed: 34 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PAYNLFormsApp/Form1.cs

Lines changed: 171 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void dumpPaymentmethodsToolStripMenuItem_Click(object sender, EventArgs
4040
DebugForm form = new DebugForm();
4141
form.dumpPaymentmethods();
4242
form.ShowDialog();
43-
43+
4444
}
4545

4646
private void ClearDebug()
@@ -80,14 +80,14 @@ private void dumpTransactionGetServiceToolStripMenuItem_Click(object sender, Eve
8080
form.dumpTransactionGetService();
8181
form.ShowDialog();
8282

83-
83+
8484
}
8585

8686
private void dumpTransactionGetLastToolStripMenuItem_Click(object sender, EventArgs e)
8787
{
8888
DebugForm form = new DebugForm();
8989
form.dumpTransactionGetLast();
90-
form.ShowDialog();
90+
form.ShowDialog();
9191
}
9292

9393
private void txinfo(string id)
@@ -223,7 +223,7 @@ private void startuseFixtureEditableToolStripMenuItem_Click(object sender, Event
223223
frm.ShowDialog();
224224
}
225225

226-
226+
227227

228228
private void frm_FormClosed(object sender, FormClosedEventArgs e)
229229
{
@@ -311,10 +311,10 @@ private void serviceCategoriesToolStripMenuItem_Click(object sender, EventArgs e
311311

312312
private void approveToolStripMenuItem_Click(object sender, EventArgs e)
313313
{
314-
314+
315315
ApproveDecline form = new ApproveDecline();
316316
form.ShowDialog();
317-
317+
318318
}
319319

320320
private void declineToolStripMenuItem_Click(object sender, EventArgs e)
@@ -323,15 +323,15 @@ private void declineToolStripMenuItem_Click(object sender, EventArgs e)
323323
ApproveDecline form = new ApproveDecline();
324324
form.ShowDialog();
325325

326-
327-
}
326+
327+
}
328328

329329
private void refundAddToolStripMenuItem_Click(object sender, EventArgs e)
330330
{
331331

332332
RefundAdd form = new RefundAdd();
333333
form.ShowDialog();
334-
334+
335335
}
336336

337337
private void refundToolStripMenuItem_Click(object sender, EventArgs e)
@@ -342,13 +342,169 @@ private void refundToolStripMenuItem_Click(object sender, EventArgs e)
342342

343343
}
344344

345+
private void testDateTimeConversionToolStripMenuItem_Click(object sender, EventArgs e)
346+
{
347+
string[] ymdtests = {
348+
// YMD
349+
@"{dt: '2018-1-1'}",
350+
@"{dt: '2018-5-10'}",
351+
@"{dt: '2018-12-11'}",
352+
@"{dt: '2018-12-1'}",
353+
@"{dt: '2018/1/1'}",
354+
@"{dt: '2018/5/10'}",
355+
@"{dt: '2018/12/11'}",
356+
@"{dt: '2018/12/1'}"
357+
};
358+
string[] dmytests = {
359+
// DMY
360+
@"{dt: '1-1-2-2018'}",
361+
@"{dt: '10-5-2018'}",
362+
@"{dt: '11-23-2018'}",
363+
@"{dt: '1-12-2018'}",
364+
@"{dt: '1/1/2/2018'}",
365+
@"{dt: '10/5/2018'}",
366+
@"{dt: '11/23/2018'}",
367+
@"{dt: '1/12/2018'}"
368+
};
369+
string[] ymdhistests = {
370+
// YMDHIS
371+
@"{dt: '2018-1-1 12:11'}",
372+
@"{dt: '2018-1-1 9:11'}",
373+
@"{dt: '2018-1-1 11:9'}",
374+
@"{dt: '2018-5-10 12:11:01'}",
375+
@"{dt: '2018-12-11 9:9:1'}",
376+
@"{dt: '2018-12-1 9:9:10'}",
377+
@"{dt: '2018-12-1 09:9:10'}",
378+
@"{dt: '2018-12-1 9:09:10'}",
379+
@"{dt: '2018/1/1 12:11'}",
380+
@"{dt: '2018/1/1 9:11'}",
381+
@"{dt: '2018/1/1 11:9'}",
382+
@"{dt: '2018/5/10 12:11:01'}",
383+
@"{dt: '2018/12/11 9:9:1'}",
384+
@"{dt: '2018/12/1 9:9:10'}",
385+
@"{dt: '2018/12/1 09:9:10'}",
386+
@"{dt: '2018/12/1 9:09:10'}"
387+
};
388+
389+
390+
foreach (string dateString in ymdtests)
391+
{
392+
try
393+
{
394+
TestYMD testObj = JsonConvert.DeserializeObject<TestYMD>(dateString);
395+
AddDebug(String.Format("Converted '{0}' to {1}.", dateString, testObj.DT.ToString()));
396+
}
397+
catch (Exception e0)
398+
{
399+
AddDebug(String.Format("Error converting '{0}' using YMD.", dateString));
400+
AddDebug(e0.Message);
401+
}
402+
}
403+
foreach (string dateString in dmytests)
404+
{
405+
try
406+
{
407+
TestDMY testObj = JsonConvert.DeserializeObject<TestDMY>(dateString);
408+
AddDebug(String.Format("Converted '{0}' to {1}.", dateString, testObj.DT.ToString()));
409+
}
410+
catch (Exception e1)
411+
{
412+
AddDebug(String.Format("Error converting '{0}' using YMD.", dateString));
413+
AddDebug(e1.Message);
414+
}
415+
}
416+
foreach (string dateString in ymdhistests)
417+
{
418+
try
419+
{
420+
TestYMDHIS testObj = JsonConvert.DeserializeObject<TestYMDHIS>(dateString);
421+
AddDebug(String.Format("Converted '{0}' to {1}.", dateString, testObj.DT.ToString()));
422+
}
423+
catch (Exception e2)
424+
{
425+
AddDebug(String.Format("Error converting '{0}' using YMD.", dateString));
426+
AddDebug(e2.Message);
427+
}
428+
}
429+
430+
}
431+
432+
private void refundtransactionToolStripMenuItem_Click(object sender, EventArgs e)
433+
{
434+
APISettings.InitAPI();
435+
ClearDebug();
436+
PAYNLSDK.API.Refund.Transaction.Request fixture = RefundTransaction.GetFixtureNoProductLines();
437+
AddDebug("Fixture loaded.");
438+
AddDebug("JSON:");
439+
AddDebug(fixture.ToString());
440+
AddDebug("PARAMS:");
441+
string qs = fixture.ToQueryString();
442+
AddDebug(qs);
443+
NameValueCollection nvc = HttpUtility.ParseQueryString(qs);
444+
string json = JsonConvert.SerializeObject(NvcToDictionary(nvc, true));
445+
AddDebug("-----");
446+
//AddDebug("PARAMS AS JSON");
447+
//AddDebug(json);
448+
DumpNvc(nvc);
449+
AddDebug("-----");
450+
AddDebug("DONE");
451+
}
452+
453+
private void refundTrasactionProductsToolStripMenuItem_Click(object sender, EventArgs e)
454+
{
455+
APISettings.InitAPI();
456+
ClearDebug();
457+
PAYNLSDK.API.Refund.Transaction.Request fixture = RefundTransaction.GetFixture();
458+
AddDebug("Fixture loaded.");
459+
AddDebug("JSON:");
460+
AddDebug(fixture.ToString());
461+
AddDebug("PARAMS:");
462+
string qs = fixture.ToQueryString();
463+
AddDebug(qs);
464+
NameValueCollection nvc = HttpUtility.ParseQueryString(qs);
465+
string json = JsonConvert.SerializeObject(NvcToDictionary(nvc, true));
466+
AddDebug("-----");
467+
//AddDebug("PARAMS AS JSON");
468+
//AddDebug(json);
469+
DumpNvc(nvc);
470+
AddDebug("-----");
471+
AddDebug("DONE");
472+
}
473+
/*
474+
class X
475+
{
476+
[JsonProperty("gender"), JsonConverter(typeof(PAYNLSDK.Converters.GenderConverter))]
477+
public PAYNLSDK.Enums.Gender Gender { get; set; }
478+
479+
}
480+
*/
481+
}
482+
483+
public class TestYMD
484+
{
485+
/// <summary>
486+
/// Merchant ID
487+
/// </summary>
488+
[JsonProperty("dt"), JsonConverter(typeof(PAYNLSDK.Converters.YMDConverter))]
489+
public DateTime? DT { get; set; }
490+
491+
}
492+
public class TestDMY
493+
{
494+
/// <summary>
495+
/// Merchant ID
496+
/// </summary>
497+
[JsonProperty("dt"), JsonConverter(typeof(PAYNLSDK.Converters.DMYConverter))]
498+
public DateTime? DT { get; set; }
499+
345500
}
346-
/*
347-
class X
501+
public class TestYMDHIS
348502
{
349-
[JsonProperty("gender"), JsonConverter(typeof(PAYNLSDK.Converters.GenderConverter))]
350-
public PAYNLSDK.Enums.Gender Gender { get; set; }
503+
/// <summary>
504+
/// Merchant ID
505+
/// </summary>
506+
[JsonProperty("dt"), JsonConverter(typeof(PAYNLSDK.Converters.YMDHISConverter))]
507+
public DateTime? DT { get; set; }
351508

352509
}
353-
*/
354-
}
510+
}

PAYNLFormsApp/PAYNLFormsApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="DebugForm.Designer.cs">
7878
<DependentUpon>DebugForm.cs</DependentUpon>
7979
</Compile>
80+
<Compile Include="Fixtures\RefundTransaction.cs" />
8081
<Compile Include="Fixtures\TransactionStart.cs" />
8182
<Compile Include="Form1.cs">
8283
<SubType>Form</SubType>

PAYNLSDK/API/Refund/Add/Response.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace PAYNLSDK.API.Refund.Add
55
{
66
public class Response : ResponseBase
77
{
8+
/// <summary>
9+
/// ID of the refund starting with 'RF-' (optional, emptyfor creditcard transactions)
10+
/// </summary>
811
[JsonProperty("refundId")]
912
public string RefundId { get; set; }
1013
}

0 commit comments

Comments
 (0)