Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
avidas committed Mar 27, 2015
2 parents cd3072f + bbd0672 commit dda7fce
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ NPM status:
[![NPM version](https://badge.fury.io/js/paypal-rest-sdk.png)](http://badge.fury.io/js/paypal-rest-sdk)
[![Dependency Status](https://david-dm.org/paypal/PayPal-node-SDK.png)](https://david-dm.org/paypal/PayPal-node-SDK)

Repository for PayPal's Node SDK (node.js version >=0.6.x) and Node samples for REST API. Refer [Node.js Sample Reference App ](https://github.com/paypal/rest-api-sample-app-nodejs) for a sample web app implementing the REST APIs.
Repository for PayPal's Node SDK (node.js version >=0.6.x) and Node samples for REST API. For a full working app and documentation, have a look at the [PayPal Node SDK Page](http://paypal.github.io/PayPal-node-SDK/).

> **v1.0.0 notice**: If upgrading from paypal rest sdk 0.*, Please view Breaking Changes in release_notes.md
> **Before starting to use the sdk, please be aware of the [existing issues and currently unavailable or upcoming features](https://github.com/paypal/PayPal-Python-SDK/wiki/Existing-Issues-and-Unavailable%5CUpcoming-features) for the REST APIs. (which the sdks are based on)**
## Installation

```sh
npm install paypal-rest-sdk
```

## Usage
To write an app using the SDK

Expand Down Expand Up @@ -129,8 +135,8 @@ grunt test (timeout is specified in milliseconds eg: 15000ms)

## Debugging

* It is recommended to provide Paypal-Debug-Id if requesting PayPal Merchant Technical Services for support. You can get access to the debug id by setting environment variable NODE_ENV=development
* The error object returned for any bad request has error.response populated with [details](https://developer.paypal.com/webapps/developer/docs/api/#errors)
* It is recommended to provide Paypal-Debug-Id if requesting PayPal Merchant Technical Services for support. You can get access to the debug id by setting environment variable NODE_ENV=development.
* The error object returned for any bad request has error.response populated with [details](https://developer.paypal.com/webapps/developer/docs/api/#errors). NODE_ENV=development setting also gives you access to stringfied response in error messages.

## Reference
[REST API Reference] (https://developer.paypal.com/webapps/developer/docs/api/)
Expand Down
8 changes: 6 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ var invoke = exports.invoke = function invoke(http_method, path, data, http_opti
//Set response to be parsed JSON object if data received is json
//expect that content-type header has application/json when it
//returns data
if (res.headers['content-type'] === "application/json") {
if (typeof res.headers['content-type'] === "string" &&
res.headers['content-type'].match(/^application\/json(?:;.*)?$/) !== null) {
response = JSON.parse(response);
}
//Set response to an empty object if no data was received
Expand All @@ -98,7 +99,7 @@ var invoke = exports.invoke = function invoke(http_method, path, data, http_opti
//for questions to merchant technical services. Similar convention
//to express.js
if (res.headers['paypal-debug-id'] !== undefined && process.env.NODE_ENV === 'development') {
console.log(res.headers['paypal-debug-id']);
console.log('paypal-debug-id: ' + res.headers['paypal-debug-id']);
}
} catch (e) {
err = new Error('Invalid JSON Response Received');
Expand All @@ -115,6 +116,9 @@ var invoke = exports.invoke = function invoke(http_method, path, data, http_opti
if (!err && (res.statusCode < 200 || res.statusCode >= 300)) {
err = new Error('Response Status : ' + res.statusCode);
err.response = response;
if (process.env.NODE_ENV === 'development') {
err.response_stringified = JSON.stringify(response);
}
err.httpStatusCode = res.statusCode;
response = null;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function clone(v) {

/**
* Merges two Objects recursively, setting property of obj1 to those of obj2
* and creating property as necessary
* and creating property as necessary.
*
* Implementation suggested by @kobalicek on https://github.com/paypal/PayPal-node-SDK/issues/69
* @param {Object} obj1
* @param {Object} obj2
* @return {Object}
Expand All @@ -52,7 +54,7 @@ var merge = exports.merge = function merge(obj1, obj2) {
}

if (obj2 === null || typeof obj2 !== "object") {
throw new TypeError("merge() - first parameter has to be an object, not " + typeof obj1 + ".");
throw new TypeError("merge() - first parameter has to be an object, not " + typeof obj2 + ".");
}

if (isArray(obj1) || isArray(obj2)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "PayPal <DL-PP-NODEJS-SDK@ebay.com> (https://developer.paypal.com/)",
"name": "paypal-rest-sdk",
"description": "SDK for PayPal REST APIs",
"version": "1.5.1",
"version": "1.5.2",
"homepage": "https://github.com/paypal/PayPal-node-SDK",
"keywords": [
"paypal",
Expand Down
6 changes: 6 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
PayPal Node SDK release notes
============================

v1.5.2
----
* Content-Type Header parsing fix
* Merge updated
* NODE_ENV=development provides stringified response

v1.5.1
----
* utils.merge patch for empty header, fixes #69 and #70
Expand Down

0 comments on commit dda7fce

Please sign in to comment.