{"action":"created","issue":{"url":"https://api.github.com/repos/paypal/PayPal-node-SDK/issues/71","labels_url":"https://api.github.com/repos/paypal/PayPal-node-SDK/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/paypal/PayPal-node-SDK/issues/71/comments","events_url":"https://api.github.com/repos/paypal/PayPal-node-SDK/issues/71/events","html_url":"https://github.com/paypal/PayPal-node-SDK/issues/71","id":59298090,"number":71,"title":"TypeError creating a charge from a Future Payment authorization","user":{"login":"knightcode","id":1806693,"avatar_url":"https://avatars.githubusercontent.com/u/1806693?v=3","gravatar_id":"","url":"https://api.github.com/users/knightcode","html_url":"https://github.com/knightcode","followers_url":"https://api.github.com/users/knightcode/followers","following_url":"https://api.github.com/users/knightcode/following{/other_user}","gists_url":"https://api.github.com/users/knightcode/gists{/gist_id}","starred_url":"https://api.github.com/users/knightcode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knightcode/subscriptions","organizations_url":"https://api.github.com/users/knightcode/orgs","repos_url":"https://api.github.com/users/knightcode/repos","events_url":"https://api.github.com/users/knightcode/events{/privacy}","received_events_url":"https://api.github.com/users/knightcode/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/paypal/PayPal-node-SDK/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":41,"created_at":"2015-02-27T21:38:39Z","updated_at":"2015-03-26T20:23:03Z","closed_at":"2015-03-26T20:23:03Z","body":"Having previously authorized a future payment and stored the refresh token in our DB, The following code is crashing the server (node.js) when payment information comes in from the iOS SDK. I've already ensured that all the data given to these objects is legit, and the `client_id` and `client_secret` were previously set by a call to `paypal.configure`.\r\n\r\n```\r\nppConf = {\r\n          mode = \"sandbox\",\r\n          correlation_id: payment.corrID,\r\n          refresh_token: paymentAuthID\r\n      };\r\ncharge = {\r\n          intent: \"sale\",\r\n          payer: {payment_method: \"paypal\"},\r\n          transactions: [{\r\n            amount: {currency: \"USD\", total: order.grandTotal / 100.0},\r\n            description: \"\"\r\n            }]\r\n      };\r\npaypal.payment.create(charge, ppConf, function (err, payment) {\r\n   ...\r\n}\r\n```\r\nThe exception:\r\n```\r\nTypeError: Cannot set property 'Paypal-Application-Correlation-Id' of undefined\r\n     at Object.executeHttp (....../node_modules/paypal-rest-sdk/lib/api.js:132:67)\r\n     at Object.create (..../node_modules/paypal-rest-sdk/lib/generate.js:27:13)\r\n```"},"comment":{"url":"https://api.github.com/repos/paypal/PayPal-node-SDK/issues/comments/86698856","html_url":"https://github.com/paypal/PayPal-node-SDK/issues/71#issuecomment-86698856","issue_url":"https://api.github.com/repos/paypal/PayPal-node-SDK/issues/71","id":86698856,"user":{"login":"knightcode","id":1806693,"avatar_url":"https://avatars.githubusercontent.com/u/1806693?v=3","gravatar_id":"","url":"https://api.github.com/users/knightcode","html_url":"https://github.com/knightcode","followers_url":"https://api.github.com/users/knightcode/followers","following_url":"https://api.github.com/users/knightcode/following{/other_user}","gists_url":"https://api.github.com/users/knightcode/gists{/gist_id}","starred_url":"https://api.github.com/users/knightcode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knightcode/subscriptions","organizations_url":"https://api.github.com/users/knightcode/orgs","repos_url":"https://api.github.com/users/knightcode/repos","events_url":"https://api.github.com/users/knightcode/events{/privacy}","received_events_url":"https://api.github.com/users/knightcode/received_events","type":"User","site_admin":false},"created_at":"2015-03-26T20:23:03Z","updated_at":"2015-03-26T20:23:03Z","body":"Solved:\r\n\r\nI don't know if this is universally the case for all mobile SDKs, but the iOS SDK produces a dictionary as follows (printing it to the console with winston flattened the hierarchy, as I copied above):\r\n```\r\nclient\r\n |- environment = \r\n |- paypal_sdk_version = \r\n |- platform = iOS\r\n |- product_name = \"PayPal iOS SDK\"\r\nresponse\r\n|- code = XXXXXXXXXXXX\r\n|- response_type = \"authorization_code\"\r\n```\r\n\r\n`generateToken` requires an object with the property, `authorization_code` , set. So marshaling all the data from SDK to SDK wasn't the way to go. The following lines fixed it for me:\r\n```\r\nif (data.response && data.response.code) {\r\n    data.authorization_code = data.response.code;\r\n}\r\npaypal.generateToken(data, function (err, rt) {\r\n    ....\r\n}\r\n```\r\n\r\nIf all the mobile SDKs produce the same data structure, it'd be worth a note in the sample or a note in the mobile SDK that only `response.code` needs to be saved. It also seems like `generateToken` should complain when given a dump from a mobile SDK... if it's too difficult to handle appropriately."}}