Activate GIft Certificate when payment is Authorized

Post feature requests to this forum and a pre-configured poll will automatically be created for you.
Post Reply
hilohattie
Ensign (ENS)
Ensign (ENS)
Posts: 6
Joined: Wed May 16, 2012 9:18 pm

Activate GIft Certificate when payment is Authorized

Post by hilohattie » Fri Dec 14, 2012 5:40 pm

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.

hilohattie
Ensign (ENS)
Ensign (ENS)
Posts: 6
Joined: Wed May 16, 2012 9:18 pm

Re: Activate GIft Certificate when payment is Authorized

Post by hilohattie » Tue Dec 18, 2012 2:15 pm

I have added this code in the checkout page

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);
								// }
                        }
                    }
                }
            }
        }
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.

crazyjoe
Commander (CMDR)
Commander (CMDR)
Posts: 172
Joined: Mon Apr 26, 2010 2:20 pm

Re: Activate GIft Certificate when payment is Authorized

Post by crazyjoe » Tue Dec 18, 2012 3:42 pm

I'm interested in this feature as well.
Crazy Joe Sadloski
Webmaster
Hot Leathers Inc.
http://www.hotleathers.com

Post Reply