Page 1 of 1

Activate GIft Certificate when payment is Authorized

Posted: Fri Dec 14, 2012 5:40 pm
by hilohattie
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.

Re: Activate GIft Certificate when payment is Authorized

Posted: Tue Dec 18, 2012 2:15 pm
by hilohattie
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.

Re: Activate GIft Certificate when payment is Authorized

Posted: Tue Dec 18, 2012 3:42 pm
by crazyjoe
I'm interested in this feature as well.