Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reservation status from "checkout_complete" to "created" #5

Open
8frogs opened this issue Mar 10, 2015 · 9 comments
Open

Update reservation status from "checkout_complete" to "created" #5

8frogs opened this issue Mar 10, 2015 · 9 comments

Comments

@8frogs
Copy link

8frogs commented Mar 10, 2015

I'am looking for a way to update only the status of a reservation:

Klarna gives a Python example:

if order['status'] == 'checkout_complete':
    # At this point make sure the order is created in your system and send a
    # confirmation email to the customer
    update_data = {}
    update_data['status'] = 'created'
    update_data['merchant_reference'] = {
        'orderid1': uuid1()
    }
    order.update(update_data)

Could you give me a hint please?
Your help is greatly appreciated.

Thanx
Jochen

@theodorton
Copy link
Contributor

Looks like we didn't support this already. We're using this gem in combination with https://github.com/Skalar/klarna-ruby to call Klarnas RPC API for reservations.

I just pushed 58b999d which allows you to update the order status.

You can try tracking the gem from master and use the following code:

# Gemfile
...
gem 'klarna-checkout', github: 'Skalar/klarna-checkout-ruby', ref: 'master'
...
client = Klarna::Checkout::Client.new
order = client.read_order(order_id)
order.status = 'created'
client.update_order(order)

Let me know if it works and I'll publish a new version to Rubygems.

@8frogs
Copy link
Author

8frogs commented Mar 10, 2015

Hello,

I get the following error message:

"http_status_code":403,"http_status_message":"Forbidden","internal_message":"'cart' can not be set at this time"}):

$klarna_client = Klarna::Checkout::Client.new({shared_secret: 'XXX', environment: :test})

order = $klarna_client.read_order(params[:klarna_order])
order.status = 'created'
$klarna_client.update_order(order)

I still run Klarna in test modus, but Klarna told me the it should work.

@theodorton
Copy link
Contributor

Okay. I'll look into this later and get back to you.

@8frogs
Copy link
Author

8frogs commented Mar 10, 2015

Hello,

ok, I know how it works:

I added some lines:

if status == 'created'

      json = json_sanitize({
        :status   => status, // the only thing you can modify when status = checkout_complete
      })


    else
    json = json_sanitize({
      :merchant_reference => (@merchant_reference && @merchant_reference.as_json),
      :purchase_country   => @purchase_country,
      :purchase_currency  => @purchase_currency,
      :locale             => @locale,
      :cart     => @cart.as_json,
      :gui      => (@gui && @gui.as_json),
      :merchant => @merchant.as_json,
      :status   => status,
      :shipping_address => (@shipping_address && @shipping_address.as_json)
    })

@8frogs
Copy link
Author

8frogs commented Mar 10, 2015

puuuh .... it does not work ... status is set correct to "created" but all other fields get cleared. Damm!

@rashidul0405
Copy link

@8frogs got any solution?

@jglauche
Copy link

jglauche commented Oct 1, 2017

@rashidul0405 I made a solution for this in my fork. I added a method to activate_order which would only send the status update to the API instead of the whole order (which did not work for me; the API seems to have a couple of different fields in the German locale)

https://github.com/Joaz/klarna-checkout-ruby

@atanana
Copy link

atanana commented Dec 6, 2017

This is a really ugly hack but it works for now

  order.status = 'created'
  order.instance_variable_set '@shipping_address', nil
  order.instance_variable_set '@cart', nil
  order.instance_variable_set '@locale', nil
  order.instance_variable_set '@purchase_currency', nil
  order.instance_variable_set '@purchase_country', nil
  order.define_singleton_method(:valid?) { return true }
  client.update_order(order)

@jesperf
Copy link

jesperf commented Mar 7, 2018

@atanana This works for me too, thanks!

Without it I received this error when trying to update the order status and merchant reference:

Klarna::Checkout::ForbiddenException: {"http_status_code":403,"http_status_message":"Forbidden","internal_message":"'shipping_address' can not be set at this time"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants