Activate GIft Certificate when payment is Authorized
-
- Ensign (ENS)
- Posts: 6
- Joined: Wed May 16, 2012 9:18 pm
Activate GIft Certificate when payment is Authorized
Can anyone help me I have setup a product as gift certificate so customer can buy it online. And is there a way to auto activate certificates when the payment is authorized? I only want to do this on gift certificates not on all products. Please I need help. Thank you.
-
- Ensign (ENS)
- Posts: 6
- Joined: Wed May 16, 2012 9:18 pm
Re: Activate GIft Certificate when payment is Authorized
I have added this code in the checkout page
It is working well but when I capture the payment it will generate another serial number and activate again the gift certificate which causes problem to customer and our side. Please anyone can help me with this.
Code: Select all
//Activate GiftCertificate
Order order = OrderDataSource.Load(e.OrderId, false);
if (order != null)
{
if (order.OrderStatus.Name == "Payment Pending")
{
foreach (OrderItem orderItem in order.Items)
{
if (orderItem.OrderItemType == OrderItemType.Product)
{
if (orderItem.Product.IsGiftCertificate)
{
// activate gift certificate
GiftCertificateCollection giftCertificates = GiftCertificateDataSource.LoadForOrderItem(orderItem.OrderItemId);
if (giftCertificates.Count > 0)
{
IGiftCertKeyProvider provider = new DefaultGiftCertKeyProvider();
foreach (GiftCertificate giftCertificate in giftCertificates)
{
giftCertificate.SerialNumber = provider.GenerateGiftCertificateKey();
giftCertificate.AddActivatedTransaction();
giftCertificate.Save();
}
}
// capture payment to activate gift certificate
// int payCount = 0;
// int paymentCount = order.Payments.Count;
// for (int i = 0; i < paymentCount; i++)
// {
// Payment payment = order.Payments[i];
// if (payment.PaymentStatus == PaymentStatus.Authorized)
// payment.Capture(payment.Amount, true);
// }
}
}
}
}
}
Re: Activate GIft Certificate when payment is Authorized
I'm interested in this feature as well.