Check out programmatically
Posted: Mon Oct 10, 2016 3:24 am
I have a mobile app which connects to an older version of AbleCommerce (R5). I've written my own web services layer to look up an existing customer (or create an anonymous user), manipulate the basket, handle shipping, taxes, payment, and coupons. But I'm stuck at the last step and actually checking out the basket. Checkout through the Able store itself works just fine.
Example code:
The payment variable is created from another method which is essentially a copy of what is in the CreditCaardPaymentForm web control.
I'm getting the following message:
I can peek into these classes with my version of Visual Studio and I don't see any properties or other constructors/methods that are exposed to allow for setting these values manually. I do see several mentions of AbleContext.Current in these classes, so that's what leads me to believe that they were only coded to initialize properly from a normal session of a user on the web site.
Is there any way around this, or another approach that I can take for checking out a user?
Example code:
Code: Select all
var basket = BasketDataSource.Load(basketId);
var checkoutService = new CommerceBuilder.Services.Checkout.CheckoutService();
var checkoutRequest = new CheckoutRequest(basket, payment);
var checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest);
Code: Select all
public Payment GetPayment(double amount, int paymentMethodId, string nameOnCard, string cardNumber, string expirationMonth, string expirationYear, string cvv)
{
var payment = new Payment
{
PaymentMethod = PaymentMethodDataSource.Load(paymentMethodId),
Amount = AlwaysConvert.ToDecimal(amount)
};
var instrumentBuilder = new AccountDataDictionary
{
["AccountName"] = nameOnCard,
["AccountNumber"] = cardNumber,
["ExpirationMonth"] = expirationMonth,
["ExpirationYear"] = expirationYear,
["SecurityCode"] = cvv
};
payment.ReferenceNumber = Payment.GenerateReferenceNumber(cardNumber);
payment.AccountData = instrumentBuilder.ToString();
return payment;
}
It looks like what is happening is that the CheckoutService that I'm creating is being initialized with default values (such as empty strings) and being returned without any of the merchant gateway (and other settings) that would normally be initialized if those were created through the normal checkout process using AbleContext.Resolve<CommerceBuilder.Services.Checkout.ICheckoutService>();"There was a problem processing your payment: (TESTMODE) The merchant login ID or password is invalid or the account is inactive."
I can peek into these classes with my version of Visual Studio and I don't see any properties or other constructors/methods that are exposed to allow for setting these values manually. I do see several mentions of AbleContext.Current in these classes, so that's what leads me to believe that they were only coded to initialize properly from a normal session of a user on the web site.
Is there any way around this, or another approach that I can take for checking out a user?