Skip to content

Commit

Permalink
Merge pull request #119 from Judopay/RecurringFlags-JR-4444
Browse files Browse the repository at this point in the history
JR-4444 InitialRecurringPayment, RecurringPaymentType and RelatedReceiptId added to PaymentModel
  • Loading branch information
Stuart-Baillie authored Dec 3, 2020
2 parents 38e1f21 + 3090726 commit 0231495
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.

## 2.2 Changes on 2020-12-01
#### Added
- InitialRecurringPayment, RecurringPaymentType and RelatedReceiptId added to PaymentModel
- Increase Api-Version from 5.6 to 5.7
#### Removed
- VisaCheckout APIs

Expand Down
1 change: 1 addition & 0 deletions JudoPayDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
appveyor.yml = appveyor.yml
CHANGELOG.md = CHANGELOG.md
Deploy.md = Deploy.md
Readme.md = Readme.md
EndProjectSection
EndProject
Global
Expand Down
20 changes: 20 additions & 0 deletions JudoPayDotNet/Enums/RecurringPaymentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace JudoPayDotNet.Enums
{
public enum RecurringPaymentType : long
{
[LocalizedDescription("Unknown")]
Unknown = 0,

/// <summary>
/// Scheduled regular payment
/// </summary>
[LocalizedDescription("RECURRING ")]
Recurring = 1,

/// <summary>
/// Unscheduled regular payment
/// </summary>
[LocalizedDescription("MIT")]
Mit = 2
}
}
2 changes: 1 addition & 1 deletion JudoPayDotNet/Http/VersioningHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class VersioningHandler : DelegatingHandler
{
public const string API_VERSION_HEADER = "api-version";

internal const string DEFAULT_API_VERSION = "5.6.0.0";
internal const string DEFAULT_API_VERSION = "5.7.0.0";

private readonly string _apiVersionValue;

Expand Down
24 changes: 23 additions & 1 deletion JudoPayDotNet/Models/PaymentModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using JudoPayDotNet.Clients;
using JudoPayDotNet.Enums;
using Newtonsoft.Json.Linq;

namespace JudoPayDotNet.Models
Expand Down Expand Up @@ -183,6 +183,16 @@ protected PaymentModel()
public string AcceptHeaders { get; set; }
// ReSharper restore UnusedAutoPropertyAccessor.Global

/// <summary>
/// Is this transaction the first transaction of a series (has continuous authority
/// been granted to the merchant by the card holder).
/// </summary>
/// <remarks>Mastercard requires that when dealing with continuous authority
/// payments this flag identifies the transaction where the card holder gave permission for
/// repeat charges.</remarks>
[DataMember(EmitDefaultValue = false)]
public bool? InitialRecurringPayment { get; set; }

/// <summary>
/// Indicates that the transaction has been given recurring authorization from the consumer
/// </summary>
Expand All @@ -195,6 +205,18 @@ protected PaymentModel()
[DataMember(EmitDefaultValue = false)]
public string DynamicDescriptor { get; set; }

/// <summary>
/// Enum for Regular Payments (recurring)
/// </summary>
[DataMember(EmitDefaultValue = false)]
public RecurringPaymentType? RecurringPaymentType { get; set; }

/// <summary>
/// Receipt ID of original authenticated transaction (for recurring payments)
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string RelatedReceiptId { get; set; }

/// <summary>
/// Allows you to set HTTP headers on requests
/// </summary>
Expand Down
41 changes: 30 additions & 11 deletions JudoPayDotNetIntegrationTests/IntegrationTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using JudoPayDotNet;
using JudoPayDotNet.Enums;
using JudoPayDotNet.Http;
using JudoPayDotNet.Models;
using Newtonsoft.Json;
Expand All @@ -29,19 +28,23 @@ protected IntegrationTestsBase()
}

protected CardPaymentModel GetCardPaymentModel(
string yourConsumerReference = null,
string cardNumber = "4976000000003436",
string cv2 = "452",
string postCode = "TR14 8PA",
bool? recurringPayment = null,
string yourConsumerReference = null,
string cardNumber = "4976000000003436",
string cv2 = "452",
string postCode = "TR14 8PA",
bool? initialRecurringPayment = null,
bool? recurringPayment = null,
string relatedReceiptId = null,
RecurringPaymentType? recurringPaymentType = null,

string judoId = null)
{
if (string.IsNullOrEmpty(yourConsumerReference))
{
yourConsumerReference = Guid.NewGuid().ToString();
}

return new CardPaymentModel
var ret = new CardPaymentModel
{
JudoId = judoId ?? Configuration.Judoid,
YourConsumerReference = yourConsumerReference,
Expand All @@ -54,9 +57,25 @@ protected CardPaymentModel GetCardPaymentModel(
Line1 = "32 Edward Street",
PostCode = postCode,
Town = "Camborne"
},
RecurringPayment = recurringPayment
}
};
if (initialRecurringPayment != null)
{
ret.InitialRecurringPayment = initialRecurringPayment;
}
if (recurringPayment != null)
{
ret.RecurringPayment = recurringPayment;
}
if (relatedReceiptId != null)
{
ret.RelatedReceiptId = relatedReceiptId;
}
if (recurringPaymentType != null)
{
ret.RecurringPaymentType = recurringPaymentType;
}
return ret;
}

protected TokenPaymentModel GetTokenPaymentModel(
Expand Down Expand Up @@ -302,7 +321,7 @@ protected WebPaymentRequestModel GetWebPaymentRequestModel()
ClientIpAddress = "127.0.0.1",
CompanyName = "Test",
Currency = "GBP",
ExpiryDate = DateTimeOffset.Now,
ExpiryDate = DateTimeOffset.Now.AddMinutes(30),
JudoId = Configuration.Judoid,
PartnerServiceFee = 10,
PaymentCancelUrl = "http://test.com",
Expand Down
59 changes: 51 additions & 8 deletions JudoPayDotNetIntegrationTests/PaymentTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using JudoPayDotNet.Enums;
using JudoPayDotNet.Models;
using NUnit.Framework;

Expand Down Expand Up @@ -44,17 +45,59 @@ public async Task ASimplePayment()
[Test]
public async Task ARecurringPayment()
{
var paymentWithCard = GetCardPaymentModel(recurringPayment: true, judoId: Configuration.Cybersource_Judoid);
var initialPaymentWithCard = GetCardPaymentModel(initialRecurringPayment: true, judoId: Configuration.Cybersource_Judoid);

var response = await JudoPayApiCyberSource.Payments.Create(paymentWithCard);
var initialResponse = await JudoPayApiCyberSource.Payments.Create(initialPaymentWithCard);

Assert.IsNotNull(response);
Assert.IsFalse(response.HasError);
Assert.AreEqual("Success", response.Response.Result);
Assert.IsNotNull(initialResponse);
Assert.IsFalse(initialResponse.HasError);
Assert.AreEqual("Success", initialResponse.Response.Result);

var paymentReceipt = response.Response as PaymentReceiptModel;
Assert.IsNotNull(paymentReceipt);
Assert.IsTrue(paymentReceipt.Recurring);
var initialPaymentReceipt = initialResponse.Response as PaymentReceiptModel;
Assert.IsNotNull(initialPaymentReceipt);
Assert.IsNull(initialPaymentReceipt.Recurring);

var recurringPaymentWithCard = GetCardPaymentModel(initialRecurringPayment: false, recurringPayment: true,
recurringPaymentType: RecurringPaymentType.Recurring, relatedReceiptId: "" + initialPaymentReceipt.ReceiptId,
judoId: Configuration.Cybersource_Judoid);

var recurringResponse = await JudoPayApiCyberSource.Payments.Create(recurringPaymentWithCard);
Assert.IsNotNull(recurringResponse);
Assert.IsFalse(recurringResponse.HasError);
Assert.AreEqual("Success", recurringResponse.Response.Result);

var recurringPaymentReceipt = recurringResponse.Response as PaymentReceiptModel;
Assert.IsNotNull(recurringPaymentReceipt);
Assert.IsTrue(recurringPaymentReceipt.Recurring);
}

[Test]
public async Task AnMitPayment()
{
var initialPaymentWithCard = GetCardPaymentModel(initialRecurringPayment: true, judoId: Configuration.Cybersource_Judoid);

var initialResponse = await JudoPayApiCyberSource.Payments.Create(initialPaymentWithCard);

Assert.IsNotNull(initialResponse);
Assert.IsFalse(initialResponse.HasError);
Assert.AreEqual("Success", initialResponse.Response.Result);

var initialPaymentReceipt = initialResponse.Response as PaymentReceiptModel;
Assert.IsNotNull(initialPaymentReceipt);
Assert.IsNull(initialPaymentReceipt.Recurring);

var mitPaymentWithCard = GetCardPaymentModel(initialRecurringPayment: false, recurringPayment: true,
recurringPaymentType: RecurringPaymentType.Mit, relatedReceiptId: "" + initialPaymentReceipt.ReceiptId,
judoId: Configuration.Cybersource_Judoid);

var mitResponse = await JudoPayApiCyberSource.Payments.Create(mitPaymentWithCard);
Assert.IsNotNull(mitResponse);
Assert.IsFalse(mitResponse.HasError);
Assert.AreEqual("Success", mitResponse.Response.Result);

var mitPaymentReceipt = mitResponse.Response as PaymentReceiptModel;
Assert.IsNotNull(mitPaymentReceipt);
Assert.IsTrue(mitPaymentReceipt.Recurring);
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Install-Package JudoPay.Net
You configure you Judopay API client when invoking the JudoPaymentsFactory.Create method. This has
three parameters; environment (Sandbox for development and testing, and Live for production), and api
token and secret. You set you API token and secret up through our [management dashboard](https://portal.judopay.com)
after creating an account. You can create a testing account by clicking "Getting Started" in our [documentation](https://www.judopay.com/docs)
after creating an account. You can create a testing account from [Apply for a Sandbox Account](https://www.judopay.com/apply-sandbox-account)

```c#
var client = JudoPaymentsFactory.Create(JudoPayDotNet.Enums.JudoEnvironment.Sandbox, "<TOKEN>", "<SECRET>");
Expand All @@ -43,10 +43,10 @@ var cardPaymentModel = new CardPaymentModel

// card details
CardNumber = "4976000000000036",
ExpiryDate = "1215",
ExpiryDate = "12/25",
CV2 = "452",

// an identifier for your customer
// a unique identifier for your customer
YourConsumerReference = "MyCustomer004",
};
```
Expand All @@ -60,7 +60,7 @@ client.Payments.Create(cardPaymentModel).ContinueWith(result =>

if (!paymentResult.HasError && paymentResult.Response.Result == "Success")
{
Console.WriteLine("Payment successful. Transaction Reference {0}", paymentResult.Response.ReceiptId);
Console.WriteLine($"Payment successful. Transaction Receipt ID {paymentResult.Response.ReceiptId}");
}

});
Expand Down

0 comments on commit 0231495

Please sign in to comment.