2009/10/31 Silvio <[email protected]>
> Hi,
>
> while writing tests for the getpaid.paypal module this came to my mind:
> the approach currently is that we don't create an order if it's not paid,
> but we instead create it after the paypal process is over and an IPN comes.
> Customer data is also collected on the paypal site.
> Some customers are propably going to place an order and for some reasons
> (computer crash or phone call etc) wait some time before paying it, or lose
> their browser session.
> I really think we should create the order object and destroy the cart
> before the customer is sent to paypal, collecting data on the
> getpaid-enabled site as well.
>
+1, a "review your order" page should be handy to create the order without
the need of js, but adds an extra click...
BTW, while implementing getpaid.nmi I faced another orders workflow problem.
There is a subcriber to the IWorkflowTransitionEvent than when the workflow
triggers to charging state tries to found the processor and call capture to
get the transaction result,
processor = component.getAdapter( context,
interfaces.IPaymentProcessor,
self.order.processor_id )
result = processor.capture( self.order, self.order.getTotalPrice() )
if result == interfaces.keys.results_async:
return
elif result == interfaces.keys.results_success:
self.order.finance_workflow.fireTransition('charge-charging')
else:
self.order.finance_workflow.fireTransition('decline-charging',
comment=result)
But we're not implementing an IPaymentProcessor, so this fails and we can't
move the order over the wf... a real pain because without it we only have
orders in the "REVIEWING" state.
My first fix was a change on payment.DefaultFinanceProcessorIntegration than
caused some problems to Brandon.
So after some testing I ended up with this solution,
First I created a new Orded class inheretied from getpaid one...
class INMIOrder(interfaces.IOrder):
"""
"""
class Order(BaseOrder):
"""
"""
implements(INMIOrder)
Now the processor implements an orderid method,
def orderid(self):
cartutil=getUtility(IShoppingCartUtility)
cart=cartutil.get(getSite())
# we'll get the order_manager, create the new order, and store it.
order_manager = getUtility(IOrderManager)
new_order_id = order_manager.newOrderId()
order = Order()
# register the payment processor name to make the workflow handlers
happy
order.processor_id = 'getpaid.nmi.processor'
# FIXME: registering an empty contact information list for now -
need to populate this from user
# if possible
order.contact_information = payment.ContactInformation()
order.billing_address = payment.BillingAddress()
order.shipping_address = payment.ShippingAddress()
order.order_id = new_order_id
# make cart safe for persistence by using pickling
order.shopping_cart = loads(dumps(cart))
order.user_id = getSecurityManager().getUser().getId()
order.finance_workflow.fireTransition('create')
order.finance_workflow.fireTransition('authorize')
order_manager.store(order)
return order.order_id
To get this working I needed my own FinanceProcessorIntegrator,
class
FinanceProcessorIntegration(payment.DefaultFinanceProcessorIntegration):
def __call__( self, event ):
# NMI processor is async, so just return
return
and register it,
<adapter
for=".nmi.INMIOrder
getpaid.core.interfaces.IDefaultFinanceWorkflow"
provides="getpaid.core.interfaces.IWorkflowPaymentProcessorIntegration"
factory=".nmi.FinanceProcessorIntegration"
/>
And thats all... now I have a working orders workflow for my offsite
processor...
IMHO this could be moved to getpaid.core.processors, so offsite processors
don't need to worry about order creation, wf states and events, only aprove
or decline orders based on external response...
Regards,
Juan Pablo
--~--~---------~--~----~------------~-------~--~----~
GetPaid for Plone: http://www.plonegetpaid.com (overview info) |
http://code.google.com/p/getpaid (code and issue tracker)
You received this message because you are subscribed to the Google Groups
"getpaid-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/getpaid-dev?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---