Repository navigation
Expand file tree
/
Copy pathSAiOSPaypalPlugin.js
More file actions
152 lines (137 loc) · 3.59 KB
/
Copy pathSAiOSPaypalPlugin.js
File metadata and controls
152 lines (137 loc) · 3.59 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// //////////////////////////////////////
// Paypal Cordova Plugin
// by Shazron Abdullah
//
// Oct 8th 2010
// Initial implementation
// Apr 9th 2012
// Updated for Cordova 1.6.0, wrapped in function closure, constants are namespaced under the global PayPal object
// e.g if it was PayPalPaymentType.DONATION before, it's PayPal.PaymentType.Donation now
// and it is also accessible under window.plugins.paypal.PaymentType.Donation
//
// /////////////////////////
var PayPal = (function() {
// /////////////////////////
/*
* buttonType (unused currently)
*/
SAiOSPaypalPlugin.ButtonType = {
'BUTTON_68x24' : 0,
'BUTTON_68x33' : 1,
'BUTTON_118x24': 2,
'BUTTON_152x33': 3,
'BUTTON_194x37': 4,
'BUTTON_278x43': 5,
'BUTTON_294x43': 6,
'BUTTON_TYPE_COUNT': 7
};
/*
* PaymentType for window.plugins.prepare
*/
SAiOSPaypalPlugin.PaymentType =
{
'HARD_GOODS': 0,
'SERVICE' : 1,
'PERSONAL' : 2,
'DONATION' : 3
};
/*
* errorType for PaypalPaymentEvent.Failed
*/
SAiOSPaypalPlugin.FailureType =
{
'SYSTEM_ERROR' : 0,
'RECIPIENT_ERROR' : 1,
'APPLICATION_ERROR' : 2,
'CONSUMER_ERROR' : 3
};
/*
* Events to listen to after a user touches the payment button
*/
SAiOSPaypalPlugin.PaymentEvent =
{
/**
* Listen for this event to signify Paypal payment success. The event object will have these properties:
* transactionID - a string value
*/
Success : "PaypalPaymentEvent.Success",
/**
* Listen for this event to signify Paypal payment canceled. The event object will have these properties:
* [no properties available]
*/
Canceled : "PaypalPaymentEvent.Canceled",
/**
* Listen for this event to signify Paypal payment failed. The event object will have these properties:
* errorType - an integer value
*/
Failed : "PaypalPaymentEvent.Failed"
};
// get local ref to global PhoneGap/Cordova/cordova object for exec function
var cordovaRef = window.PhoneGap || window.Cordova || window.cordova; // old to new fallbacks
/**
* Constructor
*/
function SAiOSPaypalPlugin()
{
}
/**
* Prepare payment type
* paymentType is from the PayPalPaymentType enum
*/
SAiOSPaypalPlugin.prototype.prepare = function(paymentType)
{
cordovaRef.exec("SAiOSPaypalPlugin.prepare", paymentType);
}
/**
* Initiate payment
*/
SAiOSPaypalPlugin.prototype.pay = function()
{
cordovaRef.exec("SAiOSPaypalPlugin.pay");
}
/**
* Sets the payment information for when the Paypal button is clicked.
* Takes in an object (paymentProperties). Properties available to be set:
* paymentCurrency - a string value (required)
* paymentAmount - a double value (required)
* itemDesc - a string value (required)
* recipient - a string value (e-mail address, required)
* merchantName - a string value (required)
*/
SAiOSPaypalPlugin.prototype.setPaymentInfo = function(paymentProperties)
{
cordovaRef.exec("SAiOSPaypalPlugin.setPaymentInfo", paymentProperties);
}
/**
* Install function
*/
SAiOSPaypalPlugin.install = function()
{
if ( !window.plugins ) {
window.plugins = {};
}
if ( !window.plugins.paypal ) {
window.plugins.paypal = new SAiOSPaypalPlugin();
}
}
/**
* Add to Cordova constructor
*/
if (cordovaRef && cordovaRef.addConstructor) {
cordovaRef.addConstructor(SAiOSPaypalPlugin.install);
} else {
console.log("PayPal Cordova Plugin could not be installed.");
return null;
}
/**
* Return constants
*/
return {
ButtonType : SAiOSPaypalPlugin.ButtonType,
PaymentType : SAiOSPaypalPlugin.PaymentType,
FailureType : SAiOSPaypalPlugin.FailureType,
PaymentEvent: SAiOSPaypalPlugin.PaymentEvent
};
// /////////////////////////
})();
// /////////////////////////