npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

paypal-adaptive

v0.4.2

Published

Paypal Adaptive (Payments & Accounts) SDK in node.js

Downloads

3,222

Readme

Adaptive Payments and Adaptive Accounts SDK

Node.js sdk for Paypal Adaptive Payments and Paypal Adaptive Accounts APIs, without dependencies

Usage

  • Add dependency 'paypal-adaptive' in your package.json file.
  • Require 'paypal-adaptive' in your file.
    var Paypal = require('paypal-adaptive');
    
    var paypalSdk = new Paypal({
        userId:    'userId',
        password:  'password',
        signature: 'signature',
        sandbox:   true //defaults to false
    });
  • Call to sdk methods or to the generic method callApi. If you get an error, you can check the response too for better error handling.
    var requestData = {
        requestEnvelope: {
            errorLanguage:  'en_US',
            detailLevel:    'ReturnAll'
        },
        payKey: 'AP-1234567890'
    };
    
    paypalSdk.callApi('AdaptivePayments/PaymentDetails', requestData, function (err, response) {
        if (err) {
            // You can see the error
            console.log(err);
            //And the original Paypal API response too
            console.log(response);
        } else {
            // Successful response
            console.log(response);
        }
    });

API

GetPaymentOptions

var payKey = 'AP-1234567890';

paypalSdk.getPaymentOptions(payKey, function (err, response) {
    if (err) {
        console.log(err);
    } else {
        // payments options for this payKey
        console.log(response);
    }
});

PaymentDetails

// One of this params is required
// The payKey
var params = {
    payKey: 'AP-1234567890'
};
// Or the transactionId
var params = {
    transactionId: 'AP-1234567890'
};
// Or the trackingId
var params = {
    trackingId: 'AP-1234567890'
};

paypalSdk.paymentDetails(params, function (err, response) {
    if (err) {
        console.log(err);
    } else {
        // payments details for this payKey, transactionId or trackingId
        console.log(response);
    }
});

Pay

var payload = {
    requestEnvelope: {
        errorLanguage:  'en_US'
    },
    actionType:     'PAY',
    currencyCode:   'USD',
    feesPayer:      'EACHRECEIVER',
    memo:           'Chained payment example',
    cancelUrl:      'http://test.com/cancel',
    returnUrl:      'http://test.com/success',
    receiverList: {
        receiver: [
            {
                email:  '[email protected]',
                amount: '100.00',
                primary:'true'
            },
            {
                email:  '[email protected]',
                amount: '10.00',
                primary:'false'
            }
        ]
    }
};

paypalSdk.pay(payload, function (err, response) {
    if (err) {
        console.log(err);
    } else {
        // Response will have the original Paypal API response
        console.log(response);
        // But also a paymentApprovalUrl, so you can redirect the sender to checkout easily
        console.log('Redirect to %s', response.paymentApprovalUrl);
    }
});

Preapproval

var payload = {
    currencyCode:                   'USD',
    startingDate:                   new Date().toISOString(),
    endingDate:                     new Date('2020-01-01').toISOString(),
    returnUrl:                      'http://your-website.com',
    cancelUrl:                      'http://your-website.com',
    ipnNotificationUrl:             'http://your-ipn-listener.com',
    maxNumberOfPayments:            1,
    displayMaxTotalAmount:          true,
    maxTotalAmountOfAllPayments:    '100.00',
    requestEnvelope: {
        errorLanguage:  'en_US'
    }
}

paypalSdk.preapproval(payload, function (err, response) {
    if (err) {
        console.log(err);
    } else {
        // Response will have the original Paypal API response
        console.log(response);
        // But also a preapprovalUrl, so you can redirect the sender to approve the payment easily
        console.log('Redirect to %s', response.preapprovalUrl);
    }
});

Note: The other API methods has default behavior by now: you send a payload and obtains the Paypal original response.

var payload = {
    requestEnvelope: {
        errorLanguage:  'en_US'
    },
    // another data required by API method
};

var callback = function (err, response) {
    if (err) {
        // Handle error
        console.log(err);
    } else {
        // Paypal response
        console.log(response)
    }
};

// For Adaptive Payments
paypalSdk.cancelPreapproval(payload, callback);

paypalSdk.convertCurrency(payload, callback);

paypalSdk.executePayment(payload, callback);

paypalSdk.getFundingPlans(payload, callback);

paypalSdk.getShippingAddresses(payload, callback);

paypalSdk.preapprovalDetails(payload, callback);

paypalSdk.setPaymentOptions(payload, callback);

// For Adaptive Accounts
paypalSdk.addBankAccount(payload, callback);

paypalSdk.addPaymentCard(payload, callback);

paypalSdk.checkComplianceStatus(payload, callback);

paypalSdk.createAccount(payload, callback);
// To use this method you can set X-PAYPAL-SANDBOX-EMAIL-ADDRESS and X-PAYPAL-DEVICE-IPADDRESS headers passing 'sandboxEmailAddress' and 'deviceIpAddress' properties on config

paypalSdk.getUserAgreement(payload, callback);

paypalSdk.getVerifiedStatus(payload, callback);

paypalSdk.setFundingSourceConfirmed(payload, callback);

paypalSdk.updateComplianceStatus(payload, callback);

Tests

Tests can be ran with:

mocha

Reference

Paypal Adaptive Payments Paypal Adaptive Accounts

License

Copyright (c) 2014 Gonzalo Aguirre. See the LICENSE file for license rights and limitations (MIT).