Customization Of Payment Gateway
Customization Of Payment Gateway
Hi,
How can we customize payment gateway in able commerce?
I am using Moneris as my payment gateway for website.
How can we customize payment gateway in able commerce?
I am using Moneris as my payment gateway for website.
Re: Customization Of Payment Gateway
If you want to customize and existing payment gateway you will first need to get the source of that payment gateway from AbleCommerce. If you are writing your own payment gateway then there is a good wiki article on how to do this. http://wiki.ablecommerce.com/index.php/ ... nt_Gateway
Re: Customization Of Payment Gateway
Hi plugables,
Thanks for your help.
I checked with URL you mentioned & trying to implement "extending PaymentProviderBase class" method.
I need to setup Recurring payment on the basis of product subscription.
But i am not getting how to access particular product's subscription which is added from able commerce admin.
That order mey contain many products ... Some of which may have recurring subscription & some may not...
So how can i get all this information in this Interface ...
I am using Moneris Payment gateway
Thanks for your help.
I checked with URL you mentioned & trying to implement "extending PaymentProviderBase class" method.
I need to setup Recurring payment on the basis of product subscription.
But i am not getting how to access particular product's subscription which is added from able commerce admin.
That order mey contain many products ... Some of which may have recurring subscription & some may not...
So how can i get all this information in this Interface ...
I am using Moneris Payment gateway
Re: Customization Of Payment Gateway
This is not for you to worry. When AbleCommerce will make a call to your payment provider it will make a call for recurring payments separately. For example DoAuthorizeRecurring will be called when AbleCommerce wants a recurring payment authorized. DoAuthorize will be called for normal payments. You just implement these methods accordingly in your custom implementation.
Re: Customization Of Payment Gateway
Hi plugables,
I implemented below method in Moneris Payment gateway custom implementation.
public override AuthorizeRecurringTransactionResponse DoAuthorizeRecurring(AuthorizeRecurringTransactionRequest authorizeRequest)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
Payment payment = authorizeRequest.Payment;
if (payment == null)
{
throw new ArgumentNullException("request.Payment");
}
Order order = payment.Order;
if (order == null)
{
throw new ArgumentNullException("request.Payment.Order");
}
User user = order.User;
Address primaryAddress = user.PrimaryAddress;
PaymentInstrument paymentInstrument = payment.PaymentMethod.PaymentInstrument;
switch (paymentInstrument)
{
case PaymentInstrument.Visa:
case PaymentInstrument.MasterCard:
case PaymentInstrument.Discover:
case PaymentInstrument.AmericanExpress:
{
AccountDataDictionary dictionary2 = new AccountDataDictionary(payment.AccountData);
string accountNumber = dictionary2.GetValue("AccountNumber");
if (base.UseDebugMode)
{
dictionary[accountNumber] = base.MakeReferenceNumber(accountNumber);
}
string str2 = dictionary2.GetValue("ExpirationMonth");
if (str2.Length == 1)
{
str2.Insert(0, "0");
}
string str3 = dictionary2.GetValue("ExpirationYear").Substring(2, 2);
string str4 = dictionary2.GetValue("SecurityCode");
if (!string.IsNullOrEmpty(str4) && base.UseDebugMode)
{
dictionary["securityCode"] = new string('x', str4.Length);
}
if (!base.UseDebugMode)
{
string str5 = string.Format("store_id={0}&api_token={1}", this.StoreID, this.APIToken);
dictionary[str5] = "store_id=xxxxxxxx&api_token=xxxxxxxx";
}
StringBuilder builder = new StringBuilder();
builder.Append("<?xml version=\"1.0\"?>");
builder.Append("<request><store_id>" + this.StoreID + "</store_id>");
builder.Append("<api_token>" + this.APIToken + "</api_token>");
builder.Append("<purchase><order_id>" + this.ComposeOrderID(primaryAddress.FirstName, primaryAddress.LastName, order.OrderId.ToString()) + "</order_id>");
//builder.Append("<cust_id>" + user.UserId.ToString() + "</cust_id>");
builder.Append("<amount>" + authorizeRequest.Amount.ToString() + "</amount>");
builder.Append("<pan>" + accountNumber + "</pan>");
builder.Append("<expdate>" + str3 + str2 + "</expdate>");
builder.Append("<crypt_type>" + this._Crypt + "</crypt_type>");
builder.Append("<recur><recur_unit>" + "WEEK" + "</recur_unit>");
builder.Append("<start_now>"+ "true" + "</start_now>");
builder.Append("<start_date>" + "2011/10/30" + "</start_date>");
builder.Append("<num_recurs>" + "4" + "</num_recurs>");
builder.Append("<period>" + "2" + "</period>");
builder.Append("<recur_amount>" + "1.00" + "</recur_amount></recur>");
builder.Append("</purchase>");
builder.Append("<res_purchase_cc><data_key>" + "RbFbmySFugYNRSmTaN6Gkm08r" + "</data_key>");
builder.Append("<order_id>" + "Moneris_test_Dec20_4" + "</order_id>");
builder.Append("<cust_id>" + "My_Customer_Name" + "</cust_id>");
builder.Append("<amount>" + "55.00" + "</amount>");
builder.Append("<crypt_type>" + "7" + "</crypt_type>");
builder.Append("<recur><recur_unit>" + "month" + "</recur_unit>");
builder.Append("<start_now>"+"true"+"</start_now>");
builder.Append("<start_date>"+"2011/12/01"+"</start_date>");
builder.Append("<num_recurs>"+"12"+"</num_recurs>");
builder.Append("<period>"+"1"+"</period>");
builder.Append("<recur_amount>"+"1.00"+"</recur_amount>");
builder.Append("</recur>");
builder.Append("</res_purchase_cc></request>");
string message = builder.ToString();
if (base.UseDebugMode)
{
base.RecordCommunication(this.Name, PaymentProviderBase.CommunicationDirection.Send, string.Format("====== DoRecurring(Purchase) ============== {0} ===========================", DateTime.Now), null);
base.RecordCommunication(this.Name, PaymentProviderBase.CommunicationDirection.Send, message, null);
}
string str8 = this.SendRequest(message);
if (base.UseDebugMode)
{
base.RecordCommunication(this.Name, PaymentProviderBase.CommunicationDirection.Receive, str8, null);
}
Transaction transaction = new Transaction();
transaction.PaymentGatewayId = base.PaymentGatewayId;
transaction.TransactionType = this.UseAuthCapture ? TransactionType.AuthorizeCapture : authorizeRequest.TransactionType;
int num = Convert.ToInt32(this.GetNodeValue(str8, "ResponseCode"));
bool flag = Convert.ToBoolean(this.GetNodeValue(str8, "Complete"));
if ((num < 50) && flag)
{
transaction.ProviderTransactionId = this.GetNodeValue(str8, "ReferenceNum");
transaction.TransactionDate = Convert.ToDateTime(this.GetNodeValue(str8, "TransDate"));
transaction.Amount = AlwaysConvert.ToDecimal(this.GetNodeValue(str8, "TransAmount"));
transaction.TransactionStatus = TransactionStatus.Successful;
transaction.ResponseCode = this.GetNodeValue(str8, "ResponseCode");
transaction.ResponseMessage = this.GetNodeValue(str8, "Message");
transaction.AuthorizationCode = this.GetNodeValue(str8, "AuthCode");
transaction.RemoteIP = authorizeRequest.RemoteIP;
AuthorizeRecurringTransactionResponse response = new AuthorizeRecurringTransactionResponse();
response.Status = transaction.TransactionStatus;
response.AddTransaction(transaction);
return response;
}
transaction.TransactionStatus = TransactionStatus.Failed;
transaction.ResponseMessage = this.GetNodeValue(str8, "ResponseCode");
AuthorizeRecurringTransactionResponse response1 = new AuthorizeRecurringTransactionResponse();
response1.Status = transaction.TransactionStatus;
response1.AddTransaction(transaction);
return response1;
}
case PaymentInstrument.Check:
throw new ArgumentException("This gateway does not support the requested payment instrument: " + paymentInstrument.ToString());
}
throw new ArgumentException("This gateway does not support the requested payment instrument: " + paymentInstrument.ToString());
}
Then i compiled my class & placed resulting dll in projects bin folder.
Fom able commerce i have added 1 product which is related to 1 subscription plan. & for that subscription plan i have Billing Option As Recurring Charge Of $10.00
And then i tried to place order with this product using my customised gateway...
Then In gateway log i checked transaction but it contains call to below:
Send: ====== DoAuthorize (Purchase) ============== 3/11/2011 1:34:46 PM ===========================
Send: <?xml version="1.0"?><request><store_id>monca06160</store_id><api_token>vtkIhG2d0yXTtbGOT6uy</api_token><purchase><order_id>WW286</order_id><cust_id>2647</cust_id><amount>7.00</amount><pan>4242424242424242</pan><expdate>2005</expdate><crypt_type>7</crypt_type></purchase></request>
Receive: <?xml version="1.0" standalone="yes"?><response><receipt><ReceiptId>null</ReceiptId><ReferenceNum>null</ReferenceNum><ResponseCode>null</ResponseCode><ISO>null</ISO><AuthCode>null</AuthCode><TransTime>null</TransTime><TransDate>null</TransDate><TransType>null</TransType><Complete>false</Complete><Message>API token mismatch</Message><TransAmount>null</TransAmount><CardType>null</CardType><TransID>null</TransID><TimedOut>false</TimedOut><BankTotals>null</BankTotals><Ticket>null</Ticket><CavvResultCode>null</CavvResultCode></receipt></response>
Its calling "oAuthorize" insteas of DoAuthorizeRecurring
Can you please let me know is this procedure right?
Or i am doing anything wrong....
I implemented below method in Moneris Payment gateway custom implementation.
public override AuthorizeRecurringTransactionResponse DoAuthorizeRecurring(AuthorizeRecurringTransactionRequest authorizeRequest)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
Payment payment = authorizeRequest.Payment;
if (payment == null)
{
throw new ArgumentNullException("request.Payment");
}
Order order = payment.Order;
if (order == null)
{
throw new ArgumentNullException("request.Payment.Order");
}
User user = order.User;
Address primaryAddress = user.PrimaryAddress;
PaymentInstrument paymentInstrument = payment.PaymentMethod.PaymentInstrument;
switch (paymentInstrument)
{
case PaymentInstrument.Visa:
case PaymentInstrument.MasterCard:
case PaymentInstrument.Discover:
case PaymentInstrument.AmericanExpress:
{
AccountDataDictionary dictionary2 = new AccountDataDictionary(payment.AccountData);
string accountNumber = dictionary2.GetValue("AccountNumber");
if (base.UseDebugMode)
{
dictionary[accountNumber] = base.MakeReferenceNumber(accountNumber);
}
string str2 = dictionary2.GetValue("ExpirationMonth");
if (str2.Length == 1)
{
str2.Insert(0, "0");
}
string str3 = dictionary2.GetValue("ExpirationYear").Substring(2, 2);
string str4 = dictionary2.GetValue("SecurityCode");
if (!string.IsNullOrEmpty(str4) && base.UseDebugMode)
{
dictionary["securityCode"] = new string('x', str4.Length);
}
if (!base.UseDebugMode)
{
string str5 = string.Format("store_id={0}&api_token={1}", this.StoreID, this.APIToken);
dictionary[str5] = "store_id=xxxxxxxx&api_token=xxxxxxxx";
}
StringBuilder builder = new StringBuilder();
builder.Append("<?xml version=\"1.0\"?>");
builder.Append("<request><store_id>" + this.StoreID + "</store_id>");
builder.Append("<api_token>" + this.APIToken + "</api_token>");
builder.Append("<purchase><order_id>" + this.ComposeOrderID(primaryAddress.FirstName, primaryAddress.LastName, order.OrderId.ToString()) + "</order_id>");
//builder.Append("<cust_id>" + user.UserId.ToString() + "</cust_id>");
builder.Append("<amount>" + authorizeRequest.Amount.ToString() + "</amount>");
builder.Append("<pan>" + accountNumber + "</pan>");
builder.Append("<expdate>" + str3 + str2 + "</expdate>");
builder.Append("<crypt_type>" + this._Crypt + "</crypt_type>");
builder.Append("<recur><recur_unit>" + "WEEK" + "</recur_unit>");
builder.Append("<start_now>"+ "true" + "</start_now>");
builder.Append("<start_date>" + "2011/10/30" + "</start_date>");
builder.Append("<num_recurs>" + "4" + "</num_recurs>");
builder.Append("<period>" + "2" + "</period>");
builder.Append("<recur_amount>" + "1.00" + "</recur_amount></recur>");
builder.Append("</purchase>");
builder.Append("<res_purchase_cc><data_key>" + "RbFbmySFugYNRSmTaN6Gkm08r" + "</data_key>");
builder.Append("<order_id>" + "Moneris_test_Dec20_4" + "</order_id>");
builder.Append("<cust_id>" + "My_Customer_Name" + "</cust_id>");
builder.Append("<amount>" + "55.00" + "</amount>");
builder.Append("<crypt_type>" + "7" + "</crypt_type>");
builder.Append("<recur><recur_unit>" + "month" + "</recur_unit>");
builder.Append("<start_now>"+"true"+"</start_now>");
builder.Append("<start_date>"+"2011/12/01"+"</start_date>");
builder.Append("<num_recurs>"+"12"+"</num_recurs>");
builder.Append("<period>"+"1"+"</period>");
builder.Append("<recur_amount>"+"1.00"+"</recur_amount>");
builder.Append("</recur>");
builder.Append("</res_purchase_cc></request>");
string message = builder.ToString();
if (base.UseDebugMode)
{
base.RecordCommunication(this.Name, PaymentProviderBase.CommunicationDirection.Send, string.Format("====== DoRecurring(Purchase) ============== {0} ===========================", DateTime.Now), null);
base.RecordCommunication(this.Name, PaymentProviderBase.CommunicationDirection.Send, message, null);
}
string str8 = this.SendRequest(message);
if (base.UseDebugMode)
{
base.RecordCommunication(this.Name, PaymentProviderBase.CommunicationDirection.Receive, str8, null);
}
Transaction transaction = new Transaction();
transaction.PaymentGatewayId = base.PaymentGatewayId;
transaction.TransactionType = this.UseAuthCapture ? TransactionType.AuthorizeCapture : authorizeRequest.TransactionType;
int num = Convert.ToInt32(this.GetNodeValue(str8, "ResponseCode"));
bool flag = Convert.ToBoolean(this.GetNodeValue(str8, "Complete"));
if ((num < 50) && flag)
{
transaction.ProviderTransactionId = this.GetNodeValue(str8, "ReferenceNum");
transaction.TransactionDate = Convert.ToDateTime(this.GetNodeValue(str8, "TransDate"));
transaction.Amount = AlwaysConvert.ToDecimal(this.GetNodeValue(str8, "TransAmount"));
transaction.TransactionStatus = TransactionStatus.Successful;
transaction.ResponseCode = this.GetNodeValue(str8, "ResponseCode");
transaction.ResponseMessage = this.GetNodeValue(str8, "Message");
transaction.AuthorizationCode = this.GetNodeValue(str8, "AuthCode");
transaction.RemoteIP = authorizeRequest.RemoteIP;
AuthorizeRecurringTransactionResponse response = new AuthorizeRecurringTransactionResponse();
response.Status = transaction.TransactionStatus;
response.AddTransaction(transaction);
return response;
}
transaction.TransactionStatus = TransactionStatus.Failed;
transaction.ResponseMessage = this.GetNodeValue(str8, "ResponseCode");
AuthorizeRecurringTransactionResponse response1 = new AuthorizeRecurringTransactionResponse();
response1.Status = transaction.TransactionStatus;
response1.AddTransaction(transaction);
return response1;
}
case PaymentInstrument.Check:
throw new ArgumentException("This gateway does not support the requested payment instrument: " + paymentInstrument.ToString());
}
throw new ArgumentException("This gateway does not support the requested payment instrument: " + paymentInstrument.ToString());
}
Then i compiled my class & placed resulting dll in projects bin folder.
Fom able commerce i have added 1 product which is related to 1 subscription plan. & for that subscription plan i have Billing Option As Recurring Charge Of $10.00
And then i tried to place order with this product using my customised gateway...
Then In gateway log i checked transaction but it contains call to below:
Send: ====== DoAuthorize (Purchase) ============== 3/11/2011 1:34:46 PM ===========================
Send: <?xml version="1.0"?><request><store_id>monca06160</store_id><api_token>vtkIhG2d0yXTtbGOT6uy</api_token><purchase><order_id>WW286</order_id><cust_id>2647</cust_id><amount>7.00</amount><pan>4242424242424242</pan><expdate>2005</expdate><crypt_type>7</crypt_type></purchase></request>
Receive: <?xml version="1.0" standalone="yes"?><response><receipt><ReceiptId>null</ReceiptId><ReferenceNum>null</ReferenceNum><ResponseCode>null</ResponseCode><ISO>null</ISO><AuthCode>null</AuthCode><TransTime>null</TransTime><TransDate>null</TransDate><TransType>null</TransType><Complete>false</Complete><Message>API token mismatch</Message><TransAmount>null</TransAmount><CardType>null</CardType><TransID>null</TransID><TimedOut>false</TimedOut><BankTotals>null</BankTotals><Ticket>null</Ticket><CavvResultCode>null</CavvResultCode></receipt></response>
Its calling "oAuthorize" insteas of DoAuthorizeRecurring
Can you please let me know is this procedure right?
Or i am doing anything wrong....
Re: Customization Of Payment Gateway
You must test by purchasing a product that has subscriptions. If you are testing with normal products DoAuthorizeRecurring will not get called.
Re: Customization Of Payment Gateway
Hi plugables,
I am doing the same.
I placed order with the product which has subscription.
& checked through manage Orders in admin ... my order contains subscription (recurring)...
But payment log says its calling DoAuthorize (Purchase) not DoAuthorizeRecurring.
Do i need to test with real payment details?
is there any way to test it locally?
I have configured Gateway Mode : Test Gateway, Test Mode locally.
I am doing the same.
I placed order with the product which has subscription.
& checked through manage Orders in admin ... my order contains subscription (recurring)...
But payment log says its calling DoAuthorize (Purchase) not DoAuthorizeRecurring.
Do i need to test with real payment details?
is there any way to test it locally?
I have configured Gateway Mode : Test Gateway, Test Mode locally.
Re: Customization Of Payment Gateway
Have you indicated via SupportedTransactions property that your gateway supports recurring payments?
Re: Customization Of Payment Gateway
Yes, i have indicated it.
public override CommerceBuilder.Payments.Providers.SupportedTransactions SupportedTransactions
{
get
{
return (
CommerceBuilder.Payments.Providers.SupportedTransactions.RecurringBilling |
CommerceBuilder.Payments.Providers.SupportedTransactions.Void |
CommerceBuilder.Payments.Providers.SupportedTransactions.Refund |
CommerceBuilder.Payments.Providers.SupportedTransactions.PartialRefund |
CommerceBuilder.Payments.Providers.SupportedTransactions.Capture |
CommerceBuilder.Payments.Providers.SupportedTransactions.AuthorizeCapture |
CommerceBuilder.Payments.Providers.SupportedTransactions.Authorize);
}
}
public override CommerceBuilder.Payments.Providers.SupportedTransactions SupportedTransactions
{
get
{
return (
CommerceBuilder.Payments.Providers.SupportedTransactions.RecurringBilling |
CommerceBuilder.Payments.Providers.SupportedTransactions.Void |
CommerceBuilder.Payments.Providers.SupportedTransactions.Refund |
CommerceBuilder.Payments.Providers.SupportedTransactions.PartialRefund |
CommerceBuilder.Payments.Providers.SupportedTransactions.Capture |
CommerceBuilder.Payments.Providers.SupportedTransactions.AuthorizeCapture |
CommerceBuilder.Payments.Providers.SupportedTransactions.Authorize);
}
}
Re: Customization Of Payment Gateway
This is strange. I cant see any reason why DoAuthorizeRecurring is not getting called.
Re: Customization Of Payment Gateway
Hey Hi plugables,
I got it working.
The problem was at "Total Number of Payments:" setting in Subscription Plan.
If i leave this field blank then it was not working.
Now i set Total Number of Payments: field to 999 then its calling DoAuthorizeRecurring.
Thanks a lot for your help.
I got it working.
The problem was at "Total Number of Payments:" setting in Subscription Plan.
If i leave this field blank then it was not working.
Now i set Total Number of Payments: field to 999 then its calling DoAuthorizeRecurring.
Thanks a lot for your help.
Re: Customization Of Payment Gateway
Hi plugables,
I want to allow client to cancel their recurring payment.
Is this possible?
And I want to send reminder mail to client 3months prior to the expiry of their subscription plan & allow them to renew their subscription.
Can you help me in this...
I want to allow client to cancel their recurring payment.
Is this possible?
And I want to send reminder mail to client 3months prior to the expiry of their subscription plan & allow them to renew their subscription.
Can you help me in this...
Re: Customization Of Payment Gateway
This can not be done using the standard payment gateway interface alone. You will need to customize the merchant admin section as well as write additional gateway methods to handle recurring payment cancellation and etc. Sending email reminders to subscribed clients can be separate customization in AbleCommerce. Someone may have already done something like this.
Re: Customization Of Payment Gateway
hmmmmm......
Thanks for your help plugables
Thanks for your help plugables