Skip to content

Commit

Permalink
Add Rapid API version support
Browse files Browse the repository at this point in the history
  • Loading branch information
incarnate committed Apr 7, 2016
1 parent 3d07474 commit 3fab445
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 2 deletions.
8 changes: 8 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

before_build:
- nuget restore

environment:
matrix:
- APIVERSION: 31
- APIVERSION: 40
1 change: 1 addition & 0 deletions eWAY.Rapid.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<add key="PASSWORD" value="API-P4ss"/>
<add key="APIKEY" value="60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR"/>
<add key="ENDPOINT" value="https://api.sandbox.ewaypayments.com/"/>
<add key="APIVERSION" value="31"/>
</appSettings>
</configuration>
33 changes: 33 additions & 0 deletions eWAY.Rapid.Tests/IntegrationTests/QueryTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,38 @@ public void QueryTransaction_InvalidInputData_ReturnVariousErrors()
Assert.IsNotNull(queryByInvoiceRefResponse.Errors);
Assert.AreEqual(queryByInvoiceRefResponse.Errors.FirstOrDefault(), "V6171");
}

[TestMethod]
public void QueryTransaction_Rapidv40_Test()
{
string version = System.Environment.GetEnvironmentVariable("APIVERSION");
int v;

if (int.TryParse(version, out v) && v > 31)
{
var client = CreateRapidApiClient();
//Arrange
var transaction = TestUtil.CreateTransaction();

//Act
var response = client.Create(PaymentMethod.Direct, transaction);
var filter = new TransactionFilter() { TransactionID = response.TransactionStatus.TransactionID };
var queryResponse = client.QueryTransaction(filter);
var queryResponse2 = client.QueryTransaction(response.TransactionStatus.TransactionID);
//Assert
Assert.IsNotNull(queryResponse);
Assert.IsNotNull(queryResponse2);
Assert.AreEqual(response.TransactionStatus.TransactionID, queryResponse.TransactionStatus.TransactionID);
Assert.AreEqual(response.TransactionStatus.TransactionID, queryResponse2.TransactionStatus.TransactionID);
Assert.AreEqual(response.TransactionStatus.Total, queryResponse2.TransactionStatus.Total);

Assert.AreEqual("036", queryResponse2.Transaction.CurrencyCode);
Assert.AreEqual(response.TransactionStatus.Total, queryResponse2.Transaction.MaxRefund);
} else
{
Assert.Inconclusive();
}

}
}
}
16 changes: 15 additions & 1 deletion eWAY.Rapid.Tests/IntegrationTests/SdkTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ public abstract class SdkTestBase
public static string PASSWORD = ConfigurationManager.AppSettings["PASSWORD"];
public static string APIKEY = ConfigurationManager.AppSettings["APIKEY"];
public static string ENDPOINT = ConfigurationManager.AppSettings["ENDPOINT"];
public static int APIVERSION = int.Parse(ConfigurationManager.AppSettings["APIVERSION"]);

protected IRapidClient CreateRapidApiClient()
{
return RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT);
var client = RapidClientFactory.NewRapidClient(APIKEY, PASSWORD, ENDPOINT);
client.SetVersion(GetVersion());
return client;
}

protected int GetVersion()
{
string version = System.Environment.GetEnvironmentVariable("APIVERSION");
int v;
if (version != null && int.TryParse(version, out v))
{
return v;
}
return APIVERSION;
}
}
}
6 changes: 6 additions & 0 deletions eWAY.Rapid/IRapidClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public interface IRapidClient
/// <param name="password">Password matching the API Key</param>
void SetCredentials(string apiKey, string password);

/// <summary>
/// Set the Rapid API version to use
/// </summary>
/// <param name="version">Rapid API version</param>
void SetVersion(int version);

/// <summary>
/// This Method is used to create a transaction for the merchant in their eWAY account
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion eWAY.Rapid/Internals/Models/TransactionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ internal class TransactionResult
public Customer Customer { get; set; }
public string CustomerNote { get; set; }
public ShippingAddress ShippingAddress { get; set; }
}

//Rapid v40 fields
public string TransactionDateTime { get; set; }
public string FraudAction { get; set; }
public bool? TransactionCaptured { get; set; }
public string CurrencyCode { get; set; }
public int? Source { get; set; }
public int? MaxRefund { get; set; }
public int? OriginalTransactionId { get; set; }
}
}
5 changes: 5 additions & 0 deletions eWAY.Rapid/Internals/RapidClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public void SetCredentials(string apiKey, string password)
_rapidService.SetCredentials(apiKey, password);
}

public void SetVersion(int version)
{
_rapidService.SetVersion(version);
}

private CreateTransactionResponse CreateInternal(PaymentMethod paymentMethod, Transaction transaction)
{
switch (paymentMethod)
Expand Down
1 change: 1 addition & 0 deletions eWAY.Rapid/Internals/Response/CreateAccessCodeResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ internal class CreateAccessCodeResponse: BaseResponse
public Payment Payment { get;set; }
public string FormActionURL { get;set; }
public string CompleteCheckoutURL { get; set; }
public string AmexECEncryptedData { get; set; }
}
}
1 change: 1 addition & 0 deletions eWAY.Rapid/Internals/Services/IRapidService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal interface IRapidService
string GetRapidEndpoint();
void SetRapidEndpoint(string value);
void SetCredentials(string apiKey, string password);
void SetVersion(int version);
bool IsValid();
List<string> GetErrorCodes();
}
Expand Down
11 changes: 11 additions & 0 deletions eWAY.Rapid/Internals/Services/RapidService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class RapidService : IRapidService
{
private string _rapidEndpoint;
private string _authenticationHeader;
private int? _version;
private bool _isValidEndPoint;
private bool _isValidCredentials;

Expand Down Expand Up @@ -242,6 +243,11 @@ private void AddHeaders(HttpWebRequest webRequest, string httpMethod)
webRequest.UserAgent = "eWAY SDK .NET " + Assembly.GetExecutingAssembly().GetName().Version;
webRequest.Method = httpMethod;
webRequest.ContentType = "application/json";

if (_version.HasValue)
{
webRequest.Headers.Add("X-EWAY-APIVERSION", _version.ToString());
}
}

private string HandleWebException(WebException ex)
Expand Down Expand Up @@ -321,6 +327,11 @@ public void SetCredentials(string apiKey, string password)
_isValidCredentials = !string.IsNullOrWhiteSpace(apiKey) && !string.IsNullOrWhiteSpace(password);
}

public void SetVersion(int version)
{
_version = version;
}

public bool IsValid()
{
return _isValidCredentials && _isValidEndPoint;
Expand Down
4 changes: 4 additions & 0 deletions eWAY.Rapid/Models/CreateTransactionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ public class CreateTransactionResponse : BaseResponse
/// The AccessCode for this transaction (can be used to call query transaction for searching before the transaction has completed processing)
/// </summary>
public string AccessCode { get; set; }
/// <summary>
/// (Rapid v40 only) A token used to configure AMEX Express Checkout
/// </summary>
public string AmexECEncryptedData { get; set; }
}
}
29 changes: 29 additions & 0 deletions eWAY.Rapid/Models/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,35 @@ public class Transaction
/// </summary>
public string LogoUrl { get; set; }

/// <summary>
/// (v40 query response only) The date and time the transaction took place
/// </summary>
public string TransactionDateTime { get; set; }
/// <summary>
/// (v40 query response only) The fraud action that occurred if any. One of NotChallenged, Allow, Review, PreAuth, Processed, Approved, Block
/// </summary>
public string FraudAction { get; set; }
/// <summary>
/// (v40 query response only) True if funds were captured in the transaction.
/// </summary>
public bool? TransactionCaptured { get; set; }
/// <summary>
/// (v40 query response only) The ISO 4217 numeric currency code (e.g. AUD = 036)
/// </summary>
public string CurrencyCode { get; set; }
/// <summary>
/// (v40 query response only) Reserved for future use
/// </summary>
public int? Source { get; set; }
/// <summary>
/// (v40 query response only) The maximum amount that could be refunded from this transaction
/// </summary>
public int? MaxRefund { get; set; }
/// <summary>
/// (v40 query response only) Contains the original transaction ID if the queried transaction is a refund
/// </summary>
public int? OriginalTransactionId { get; set; }

/// <summary>
/// Initializes a new instance of the Transaction class
/// </summary>
Expand Down

0 comments on commit 3fab445

Please sign in to comment.