Skip to content

Commit

Permalink
Merge branch 'rolandh-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
incarnate committed Nov 20, 2017
2 parents 9568097 + 7711862 commit 90db70f
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 320 deletions.
2 changes: 1 addition & 1 deletion eWAY.Rapid.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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"/>
<add key="APIVERSION" value="40"/>
</appSettings>
</configuration>
14 changes: 14 additions & 0 deletions eWAY.Rapid/Internals/Mappings/CustomMapProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using AutoMapper;
using eWAY.Rapid.Models;
using Option = eWAY.Rapid.Internals.Models.Option;

namespace eWAY.Rapid.Internals.Mappings {
internal class CustomMapProfile : Profile {
public CustomMapProfile() {
CreateMap<String, Option>(MemberList.None).ConvertUsing(s => new Option { Value = s });
CreateMap<Option, String>(MemberList.None).ConvertUsing(o => o.Value);
CreateMap<bool?, TransactionStatus>(MemberList.None).AfterMap((b, t) => t.Status = b);
}
}
}
144 changes: 144 additions & 0 deletions eWAY.Rapid/Internals/Mappings/EntitiesMapProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using AutoMapper;
using eWAY.Rapid.Internals.Models;
using eWAY.Rapid.Internals.Response;
using eWAY.Rapid.Models;
using Customer = eWAY.Rapid.Models.Customer;
using Option = eWAY.Rapid.Internals.Models.Option;

namespace eWAY.Rapid.Internals.Mappings {
internal class EntitiesMapProfile : Profile {
public EntitiesMapProfile() {
AllowNullCollections = true;
AllowNullDestinationValues = true;

CreateMap<ShippingDetails, Models.ShippingAddress>()
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.ShippingAddress.City))
.ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.ShippingAddress.Country))
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.ShippingAddress.State))
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.ShippingAddress.PostalCode))
.ForMember(dest => dest.Street1, opt => opt.MapFrom(src => src.ShippingAddress.Street1))
.ForMember(dest => dest.Street2, opt => opt.MapFrom(src => src.ShippingAddress.Street2))
.ForMember(dest => dest.ShippingMethod, opt => opt.MapFrom(src => src.ShippingMethod.ToString()))
.ReverseMap();

CreateMap<Address, Models.ShippingAddress>()
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.City))
.ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Country))
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.State))
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.PostalCode))
.ForMember(dest => dest.Street1, opt => opt.MapFrom(src => src.Street1))
.ForMember(dest => dest.Street2, opt => opt.MapFrom(src => src.Street2))
.ReverseMap();

CreateMap<RefundDetails, Models.Refund>()
.ForMember(dest => dest.TransactionID, opt => opt.MapFrom(src => src.OriginalTransactionID.ToString()));

CreateMap<Models.Refund, RefundDetails>()
.ForMember(dest => dest.OriginalTransactionID, opt => opt.MapFrom(src => int.Parse(src.TransactionID)));

long? nullableTokenId = null;

CreateMap<Customer, Models.Customer>()
.ForMember(dest => dest.TokenCustomerID, opt => opt.MapFrom(src => string.IsNullOrWhiteSpace(src.TokenCustomerID) ? nullableTokenId : long.Parse(src.TokenCustomerID)))
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.Address.City))
.ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Address.Country))
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.Address.PostalCode))
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.Address.State))
.ForMember(dest => dest.Street1, opt => opt.MapFrom(src => src.Address.Street1))
.ForMember(dest => dest.Street2, opt => opt.MapFrom(src => src.Address.Street2)).ReverseMap();

CreateMap<Models.Customer, Customer>()
.ForMember(dest => dest.Address, opt => opt.MapFrom(src => src));

CreateMap<Models.ShippingAddress, ShippingDetails>()
.ForMember(dest => dest.ShippingAddress, opt => opt.MapFrom(src => src));

CreateMap<Models.Customer, Address>()
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.City))
.ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Country))
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.PostalCode))
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.State))
.ForMember(dest => dest.Street1, opt => opt.MapFrom(src => src.Street1))
.ForMember(dest => dest.Street2, opt => opt.MapFrom(src => src.Street2));

CreateMap<CreateAccessCodeResponse, Transaction>()
.ForMember(dest => dest.Customer, opt => opt.MapFrom(src => src.Customer))
.ForMember(dest => dest.PaymentDetails, opt => opt.MapFrom(src => src.Payment));

CreateMap<DirectTokenCustomer, Customer>()
.ForMember(dest => dest.Address, opt => opt.MapFrom(src => src))
.ReverseMap();

CreateMap<DirectTokenCustomer, Address>()
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.City))
.ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Country))
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.PostalCode))
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.State))
.ForMember(dest => dest.Street1, opt => opt.MapFrom(src => src.Street1))
.ForMember(dest => dest.Street2, opt => opt.MapFrom(src => src.Street2)).ReverseMap();

CreateMap<TokenCustomer, Customer>()
.ForMember(dest => dest.Address, opt => opt.MapFrom(src => src))
.ReverseMap();

CreateMap<TokenCustomer, Address>()
.ForMember(dest => dest.City, opt => opt.MapFrom(src => src.City))
.ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Country))
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.PostalCode))
.ForMember(dest => dest.State, opt => opt.MapFrom(src => src.State))
.ForMember(dest => dest.Street1, opt => opt.MapFrom(src => src.Street1))
.ForMember(dest => dest.Street2, opt => opt.MapFrom(src => src.Street2)).ReverseMap();

CreateMap<Customer, TokenCustomer>()
.ForMember(dest => dest.CardExpiryMonth, opt => opt.MapFrom(src => src.CardDetails.ExpiryMonth))
.ForMember(dest => dest.CardExpiryYear, opt => opt.MapFrom(src => src.CardDetails.ExpiryYear))
.ForMember(dest => dest.CardIssueNumber, opt => opt.MapFrom(src => src.CardDetails.IssueNumber))
.ForMember(dest => dest.CardName, opt => opt.MapFrom(src => src.CardDetails.Name))
.ForMember(dest => dest.CardNumber, opt => opt.MapFrom(src => src.CardDetails.Number))
.ForMember(dest => dest.CardStartMonth, opt => opt.MapFrom(src => src.CardDetails.StartMonth))
.ForMember(dest => dest.CardStartYear, opt => opt.MapFrom(src => src.CardDetails.StartYear))
.IncludeBase<Customer, Models.Customer>()
.ReverseMap();

CreateMap<Customer, DirectTokenCustomer>()
.IncludeBase<Customer, TokenCustomer>()
.ReverseMap();

CreateMap<Rapid.Models.ShippingAddress, Models.ShippingAddress>()
.ReverseMap();

CreateMap<Rapid.Models.LineItem, Models.LineItem>()
.ReverseMap();

CreateMap<Rapid.Models.Option, Models.Option>()
.ReverseMap();

CreateMap<Rapid.Models.PaymentDetails, Models.Payment>()
.ReverseMap();

CreateMap<Rapid.Models.CardDetails, Models.CardDetails>()
.ReverseMap();

CreateMap<Rapid.Models.Verification, Models.VerificationResult>()
.ReverseMap();

CreateMap<Rapid.Models.VerificationResult, Rapid.Models.Verification>()
.ReverseMap();

CreateMap<Rapid.Models.VerificationResult, Models.VerificationResult>()
.ReverseMap();

CreateMap<Rapid.Models.Payment, Models.Payment>()
.ReverseMap();

CreateMap<Rapid.Models.SettlementSummary, Models.SettlementSummary>()
.ReverseMap();

CreateMap<Rapid.Models.SettlementTransaction, Models.SettlementTransaction>()
.ReverseMap();

CreateMap<Rapid.Models.BalanceSummaryPerCardType, Models.BalanceSummaryPerCardType>()
.ReverseMap();
}
}
}
62 changes: 62 additions & 0 deletions eWAY.Rapid/Internals/Mappings/RequestMapProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using AutoMapper;
using eWAY.Rapid.Internals.Enums;
using eWAY.Rapid.Internals.Request;
using eWAY.Rapid.Models;
using Customer = eWAY.Rapid.Models.Customer;
using Refund = eWAY.Rapid.Models.Refund;

namespace eWAY.Rapid.Internals.Mappings {
internal class RequestMapProfile : Profile {
public RequestMapProfile() {
AllowNullCollections = true;
AllowNullDestinationValues = true;

CreateMap<Transaction, DirectPaymentRequest>(MemberList.None)
.ForMember(dest => dest.Items, opt => opt.MapFrom(src => src.LineItems))
.ForMember(dest => dest.ShippingAddress, opt => opt.MapFrom(src => src.ShippingDetails))
.ForMember(dest => dest.Payment, opt => opt.MapFrom(src => src.PaymentDetails))
.ForMember(dest => dest.Method, opt => opt.MapFrom(src => src.Capture ? Method.ProcessPayment : Method.Authorise));

CreateMap<Transaction, CreateAccessCodeRequest>(MemberList.None)
.ForMember(dest => dest.Items, opt => opt.MapFrom(src => src.LineItems))
.ForMember(dest => dest.ShippingAddress, opt => opt.MapFrom(src => src.ShippingDetails))
.ForMember(dest => dest.Payment, opt => opt.MapFrom(src => src.PaymentDetails))
.ForMember(dest => dest.Method, opt => opt.MapFrom(src => src.Capture
? (src.Customer.TokenCustomerID == null && src.SaveCustomer != true ? Method.ProcessPayment : Method.TokenPayment)
: Method.Authorise));

CreateMap<Transaction, CapturePaymentRequest>(MemberList.None)
.ForMember(dest => dest.Payment, opt => opt.MapFrom(src => src.PaymentDetails))
.ForMember(dest => dest.TransactionId, opt => opt.MapFrom(src => src.AuthTransactionID)).ReverseMap();

CreateMap<Transaction, CreateAccessCodeSharedRequest>()
.IncludeBase<Transaction, CreateAccessCodeRequest>();

CreateMap<Customer, DirectPaymentRequest>(MemberList.None)
.ForMember(dest => dest.Method, opt => opt.UseValue(Method.CreateTokenCustomer))
.ForMember(dest => dest.TransactionType, opt => opt.UseValue(TransactionTypes.Purchase))
.ForMember(dest => dest.Customer, opt => opt.MapFrom(src => src));

CreateMap<Customer, CreateAccessCodeRequest>(MemberList.None)
.ForMember(dest => dest.Method, opt => opt.UseValue(Method.CreateTokenCustomer))
.ForMember(dest => dest.Customer, opt => opt.MapFrom(src => src));

CreateMap<Customer, CreateAccessCodeSharedRequest>(MemberList.None)
.IncludeBase<Customer, CreateAccessCodeRequest>();

CreateMap<Refund, DirectRefundRequest>(MemberList.None)
.ForMember(dest => dest.Items, opt => opt.MapFrom(src => src.LineItems))
.ForMember(dest => dest.ShippingAddress, opt => opt.MapFrom(src => src.ShippingDetails))
.ForMember(dest => dest.Refund, opt => opt.MapFrom(src => src.RefundDetails));

CreateMap<CapturePaymentRequest, DirectCapturePaymentRequest>(MemberList.None)
.ReverseMap();

CreateMap<CancelAuthorisationRequest, DirectCancelAuthorisationRequest>(MemberList.None)
.ReverseMap();

CreateMap<Transaction, DirectAuthorisationRequest>(MemberList.None)
.IncludeBase<Transaction, DirectPaymentRequest>();
}
}
}
Loading

0 comments on commit 90db70f

Please sign in to comment.