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?