carviaso / google-checkout-dotnet-sample-code

Automatically exported from code.google.com/p/google-checkout-dotnet-sample-code
0 stars 0 forks source link

Add util method to extract shipping method name from NewOrderNotification #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The code for extracting the chosen shipping method from the
NewOrderNotification is somewhat painful. To make sure it doesn't break,
you may have to do something like this:

if (N1.orderadjustment != null) {
  if (N1.orderadjustment.shipping != null) {
    if (N1.orderadjustment.shipping.Item != null) {
      FlatRateShippingAdjustment A = (FlatRateShippingAdjustment)
N1.orderadjustment.shipping.Item;
      string ShippingMethod = A.shippingname;
    }
  }
}

And it would be different for merchant-calculated shipping. Not
surprisingly, new Checkout developers have a hard time coming up with this
code themselves. So we may want to add a util method somewhere that would
enable them to do this:

string ShippingMethod = Util.GetShippingMethod(N1);

It could check for both flat-rate and merchant-calculated shipping methods,
and any other that may be added in the future. If there is no shipping
method, it could return something sensible like empty string, instead of
thowing an exception.

Original issue reported on code.google.com by martin.o...@gmail.com on 3 Apr 2007 at 9:23

GoogleCodeExporter commented 9 years ago
How about this, return a wrapper class that contains the string, and an enum 
type, 
to tell the user what "Type" of shipping was selected.

GCheckoutShipping ship = Util.GetShippingMethod(N1);

if (ship.ShippingType = ShippingType.FlatRateShippingAdjustment)
//do something crazy here :)
else if (ship.ShippingType = ShippingType.MerchantCalculated)

This way, we really can also return a pointer to the object if needed, or allow 
the 
class to be extended.

Original comment by joseph.f...@gmail.com on 3 Apr 2007 at 9:34

GoogleCodeExporter commented 9 years ago
I like the idea of extending the NewOrderNotification class. That might work 
well
across all types of notifications, as we will no doubt run into similar issues 
in the
future.

Original comment by martin.o...@gmail.com on 3 Apr 2007 at 9:43

GoogleCodeExporter commented 9 years ago
Martin
Should we try to get this into the v1.2 release?

Original comment by joseph.f...@gmail.com on 7 Apr 2007 at 3:46

GoogleCodeExporter commented 9 years ago
Let's do this for version 1.3.

Original comment by martin.o...@gmail.com on 15 Apr 2007 at 12:54

GoogleCodeExporter commented 9 years ago
Will do.

Original comment by joseph.f...@gmail.com on 15 Apr 2007 at 1:06

GoogleCodeExporter commented 9 years ago
The first pass has been checked in
It allows for messages to be inherited and then you can add methods and 
properties 
to that new object.

Original comment by joseph.f...@gmail.com on 2 Aug 2007 at 6:05

GoogleCodeExporter commented 9 years ago
This has been added to the project.

Samples will be build to provide an example.

Original comment by joseph.f...@gmail.com on 4 Oct 2007 at 12:38