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

Added method to create one-time payment #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions lib/Paypal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,61 @@ class Paypal

callback err, response


# Creates a onetime payment profile for your customer by invoking the
# "DoExpressCheckoutPayment" method in the PayPal API.
#
# To do this, you need to pass the function the unique token that you
# recieve as a querystring appended to your RETURNURL sent to PayPal
# using the above authenticate() method.
#
# This method takes below arguments:
# token (string) The token as described above
# payerid (string) The PayPal ID of the owner of the to-become subscriber
# opts (object) The object containing the options you want to send to PayPal
# callback (function) The Callback function that is invoked on API return
#
# Note that if you do not pass a PROFILESTARTDATE in the ops object, a PROFILESTARTDATE
# with current time will be used to start the recurring payment immediately.
#
# Related API documentation:
# https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/
#
createPayment: (token, payerid, opts, callback) ->

self = @

# Check for required arguments and params and throw error(s) if they aren't available
throw new Error "Missing required token" unless token
throw new Error "Missing payerid" unless payerid

reqs = [
"DESC",
"PAYMENTREQUEST_0_AMT"
]

for i in reqs
throw new Error "Missing param " + i if !opts[i]

# Merge given params with default params for this type of API request.
opts = @_merge({
METHOD: "DoExpressCheckoutPayment"
TOKEN: token
PAYERID: payerid
PAYMENTREQUEST_0_PAYMENTACTION: "Sale"
PAYMENTREQUEST_0_AMT: 0
}, opts)

console.log opts

@makeAPIrequest @getParams(opts), (err, response) ->

return callback err, null if err

return callback err ? true, null if response["ACK"] isnt "Success"

callback err, response

# Returns subscription information for an already created subscription by
# invoking the "GetRecurringPaymentsProfileDetails" method in the PayPal API.
#
Expand Down