Payment.Capture() and Order.PaymentStatus

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Payment.Capture() and Order.PaymentStatus

Post by AbleMods » Mon Dec 15, 2008 6:53 pm

take a look at this code:

Code: Select all

           If _Order.PaymentStatus <> OrderPaymentStatus.Paid Then
                For Each _Payment As Payment In _Order.Payments
                    If _Payment.PaymentStatus = PaymentStatus.Authorized Then
                        ' capture payment and exit loop
                        _Payment.Capture(_Order.TotalCharges, True, True, "127.0.0.1")
                        Exit For
                    End If
                Next
                If _Order.PaymentStatus <> OrderPaymentStatus.Paid Then
                    ' problem capturing payment, abort auto-processing
                    Return
                End If
            End If
First, notice the elegant readability of VB code :)

Second, despite a single authorization being correctly captured the _Order.PaymentStatus is not reporting as paid immediately after payment capture.

Why? Is there some sort of child-update that has to occur on _Order to reflect the change in payment status?
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Payment.Capture() and Order.PaymentStatus

Post by nickc » Mon Dec 15, 2008 7:08 pm

Here's what I do after capture, which seems to sort things out:

Code: Select all

    order.UpdateOrderStatus((int)CommerceBuilder.Orders.OrderAction.ProcessPayments);

afm
Captain (CAPT)
Captain (CAPT)
Posts: 339
Joined: Thu Nov 03, 2005 11:52 pm
Location: Portland, OR
Contact:

Re: Payment.Capture() and Order.PaymentStatus

Post by afm » Mon Dec 15, 2008 8:16 pm

Or, more elegantly :wink:

Code: Select all

_Order.UpdateOrderStatus(CType(CommerceBuilder.Orders.OrderAction.ProcessPayments, Integer))
You could also reload the order and get any other changes at the same time.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Payment.Capture() and Order.PaymentStatus

Post by AbleMods » Mon Dec 15, 2008 8:42 pm

Interesting - didn't realize I needed to call the Updatestatus on the order but makes sense. Just figured it was a dynamic Get/Set and returned current order status.

A number of things are odd about how the code functions:
1. Even if I step through at debugger and fire the capture, it'll continually report "CapturePending" as the _Payment.PaymentStatus. Can sit there for 30 secs and still do the same.

2. The async parameter of the capture function seems to have no effect. I presumed it would pause code if set True i.e. wait until capture response received before proceeding. This doesn't appear to be the case. Tried both ways and didn't notice any difference. Shrug.

3. If indeed the payment is "CapturePending" and not "Captured", then I guess _Order status is correct - technically the payment hasn't yet been officially captured.

Thanks for the help, I think your suggestion will fix it.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Payment.Capture() and Order.PaymentStatus

Post by draneb » Mon Dec 15, 2008 10:03 pm

I wished I understood you all.

Is this what you are referring to...

I will go into my Admin and I will see an order labeled "New". If I go into the Order Payments there is credit card information there but I have to select "Authorize Payment" and then it will go through (and marked Paid Full) or be declined.

But, I use Authorize.net and all this is supposed to happen before it reaches me.
I don't understand why I receive some orders like this...

Like your post title, it seems like it is not Capturing the payment automatically sometimes.
Is this what you are discussing in this thread?
AC 7.0.3 build 13937

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Payment.Capture() and Order.PaymentStatus

Post by AbleMods » Mon Dec 15, 2008 10:29 pm

Close, but no :)

What we're doing is trying to capture order payments through our own code on the back-end of things.

I've written some new automation for my solunar fishing and hunting times. Now, when a new order is saved to my store, a routine I've written fires off.

It first checks the order for solunar times being purchased. If they are purchased, it captures the payment, calculates the solunar times, emails the customer with the times attached as a PDF and then marks the order as shipped.

Once I get it done, I will have completely eliminated the daily processing steps for filling fishing/hunting times orders. Next stop, auto-upload of orders to my distributors. Then it'll be auto-download of distributor invoices so I can automatically post shipments and tracking numbers.

I'm on a huge automation kick this month - I have named it "Operation Plate Too Full " :P
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Payment.Capture() and Order.PaymentStatus

Post by nickc » Wed Dec 17, 2008 11:39 am

I was wondering what would happen when you hit 2,000 posts.
Welcome, you are.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Payment.Capture() and Order.PaymentStatus

Post by AbleMods » Wed Dec 17, 2008 1:30 pm

Wow :shock:

I never even noticed it until you said something. Thanks!

Now that I'm on the Jedi Council, maybe I can get some things done around here :P
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

Post Reply