-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayjaq_test.coffee
92 lines (82 loc) · 2.21 KB
/
payjaq_test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
###
Show example usage with static test data
###
payjaq = require "./payjaq"
###
Exercise the functions in payjaq
###
test = () ->
console.log "Run usage examples"
client_id = 'EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp'
client_secret = 'EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp'
###
Get a token that will be used to credential the remaining ops
###
payjaq.getToken client_id, client_secret, (res) ->
token = res.access_token
console.log " "
###
Get 10 payments
###
payjaq.getPaymentsPaged token, (res) ->
console.log " "
###
Get a payment by id
###
fakeid = res.payments[0].id
payjaq.getPaymentById fakeid, token
console.log " "
###
Get your payments of status approved
###
payjaq.getApprovedPayments token
console.log " "
###
Make a test object
###
test_payment =
intent: "sale"
payer:
payment_method: "credit_card"
funding_instruments: [credit_card:
number: "4417119669820331"
type: "visa"
expire_month: 11
expire_year: 2018
cvv2: 874
first_name: "Joe"
last_name: "Shopper"
billing_address:
line1: "52 N Main ST"
city: "Johnstown"
country_code: "US"
postal_code: "43210"
state: "OH"
]
transactions: [
amount:
total: "7.47"
currency: "USD"
details:
subtotal: "7.41"
tax: "0.03"
shipping: "0.03"
description: "This is the FAKE transaction description."
]
###
Create a payment with the test object
###
payjaq.createPayment test_payment, token, (res) ->
console.log "created payment.id == " , res.id
console.log " "
###
Executing that payment will fail as is
###
console.log "Note: EXPECTED to ERROR: PAYMENT_STATE_INVALID until"
console.log "you get your own PayPal sandbox account for live objects."
payer =
payer_id : "7E7MGXCWTTKK2"
payjaq.executePayment res.id, payer, token, (res) ->
console.log "EXECUTE result: ", res
console.log " "
test()