-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlm_paypal.install
565 lines (548 loc) · 21.6 KB
/
lm_paypal.install
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<?php
/**
* @file
*
* Install or update the PayPal interface.
*
* These database fields are from:
* https://www.paypal.com/en_US/pdf/PP_OrderManagement_IntegrationGuide.pdf
* See also:
* https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
* https://www.paypal.com/uk/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside
*/
// TODO: Once I've been running lm_paypal for a while work out which
// IPN fields are unnecessary and remove them.
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function lm_paypal_uninstall() {
// TODO The drupal_(un)install_schema functions are called automatically in D7.
// drupal_uninstall_schema('lm_paypal')
variable_del('lm_paypal_debug');
variable_del('lm_paypal_host');
variable_del('lm_paypal_business');
variable_del('lm_paypal_obey_test_ipns');
variable_del('lm_paypal_ipns_max_age');
variable_del('lm_paypal_js_hide_email'); // old
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function lm_paypal_schema() {
// This table definition corresponds to the HTTP POST sent to the site by
// paypal.com. This appears to change every so often, without any notification,
// breaking live sites.
// See https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
$schema['lm_paypal_ipns'] = array(
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'My ID for received IPNs',
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'unix time when ipn arrived',
),
'txn_id' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => '',
'description' => 'Paypal generated transaction id',
),
'processed' => array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'description' => 'set if processed',
),
'test_ipn' => array(
'type' => 'int',
'size' => 'tiny',
'description' => 'only set by sandbox to 1',
),
'notify_version' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'the version number of Instant Payment Notification that makes the post.',
),
'verify_sign' => array(
'type' => 'varchar',
'length' => 120,
'description' => 'an encrypted string used to validate the authenticity of the transaction.',
),
'ipn' => array(
'type' => 'text',
'size' => 'medium',
'description' => 'The full HTTP POST data for the IPN from paypal.',
),
'ipn_track_id' => array(
'type' => 'text',
'size' => 'medium',
'description' => 'Tracking id', //@TODO better desc
),
# Website Payments Standard, Website Payments Pro, and Refund Information
# SOME FIELDS OMITTED
'parent_txn_id' => array(
'type' => 'varchar',
'length' => 28,
'description' => 'In the case of a refund, reversal, or canceled reversal, this variable contains the txn_id of the original transaction, while txn_id contains a new ID for the new transaction.',
),
'payment_date' => array(
'type' => 'varchar',
'length' => 28,
'description' => 'Time/Date stamp generated by PayPal , in the following format: HH:MM:SS DD Mmm YY, YYYY PST',
),
'payment_status' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Canceled_Reversal,Completed,Denied,Expired,Failed,In-Progress,Partially-Refunded,Pending,Processed,Refunded,Reversed,Voided',
),
'payment_type' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'echeck,instant',
),
'pending_reason' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'address,authorization,echeck,intl,multicurrency,unilateral,upgrade,verify,other',
),
'reason_code' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'chargeback,guarantee,buyer-complaint,refund,other',
),
# Buyer Information (verified 4 Jan 08)
'payer_email' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Customers primary email address. Use this email to provide any credits.',
),
'first_name' => array(
'type' => 'varchar',
'length' => 64,
'description' => 'Customers first name',
),
'last_name' => array(
'type' => 'varchar',
'length' => 64,
'description' => 'Customers last name',
),
'payer_business_name' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Customers company name, if customer represents a business',
),
'address_name' => array(
'type' => 'varchar',
'length' => 128,
'description' => 'Name used with address (included when the customer provides a Gift Address)',
),
'address_street' => array(
'type' => 'varchar',
'length' => 200,
'description' => 'Customers street address',
),
'address_city' => array(
'type' => 'varchar',
'length' => 40,
'description' => 'City of customers address',
),
'address_zip' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Zip code of customers address.',
),
'address_country' => array(
'type' => 'varchar',
'length' => 64,
'description' => 'Country of customers address.',
),
'address_country_code' => array(
'type' => 'varchar',
'length' => 2,
'description' => 'Two-character ISO 3166 country code',
),
'address_state' => array(
'type' => 'varchar',
'length' => 40,
'description' => 'State of customers address',
),
'address_status' => array(
'type' => 'varchar',
'length' => 40,
'description' => 'Customer provided a confirmed|unconfirmed address.',
),
'payer_id' => array(
'type' => 'varchar',
'length' => 13,
'description' => 'Unique customer ID.',
),
'payer_status' => array(
'type' => 'varchar',
'length' => 40,
'description' => 'Customer has a verified|unverified PayPal account.',
),
'contact_phone' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Customer�s telephone number.',
),
'residence_country' => array(
'type' => 'varchar',
'length' => 2,
'description' => 'Two-character ISO 3166 country code',
),
# Basic Information (verified 4 Jan 08)
'business' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Email address or account ID of the payment recipient (that is, the merchant). Equivalent to the values of receiver_email (if payment is sent to primary account) and business set in the Website Payment HTML. NOTE: The value of this variable is normalized to lowercase characters.',
),
'item_name' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Item name as passed by you, the merchant. Or, if not passed by you, as entered by your customer. If this is a shopping cart transaction, PayPal will append the number of the item (e.g., item_name1, item_name2).',
),
'item_number' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Pass-through variable for you to track purchases. It will get passed back to you at the completion of the payment. If omitted, no variable will be passed back to you.',
),
'quantity' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Quantity as entered by your customer or as passed by you, the merchant.',
),
'receiver_email' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Primary email address of the payment recipient (that is, the merchant). If the payment is sent to a non-primary email address on your PayPal account, the receiver_email is still your primary email. NOTE: The value of this variable is normalized to lowercase characters.',
),
'receiver_id' => array(
'type' => 'varchar',
'length' => 13,
'description' => 'Unique account ID of the payment recipient (i.e., the merchant). This is the same as the recipient\'s referral ID.',
),
# Advanced and Custom Information
'shipping' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Shipping charges associated with this transaction.',
),
'custom' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'Custom value as passed by you, the merchant. These are passthrough variables that are never presented to your customer',
),
'invoice' => array(
'type' => 'varchar',
'length' => 127,
'description' => 'Passthrough variable you can use to identify your Invoice Number for this purchase. If omittted, no variable is passed back.',
),
'memo' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'Memo as entered by your customer in PayPal Website Payments note field.',
),
'option_name1' => array(
'type' => 'varchar',
'length' => 64,
'description' => 'Option 1 name as requested by you.',
),
'option_name2' => array(
'type' => 'varchar',
'length' => 64,
'description' => 'Option 2 name as requested by you.',
),
'option_selection1' => array(
'type' => 'varchar',
'length' => 200,
'description' => 'Option 1 choice as entered by your customer.',
),
'option_selection2' => array(
'type' => 'varchar',
'length' => 200,
'description' => 'Option 2 choice as entered by your customer.',
),
'tax' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Amount of tax charged on payment.',
),
# SOME FIELDS OMITTED
'mc_currency' => array(
'type' => 'varchar',
'length' => 3,
'description' => 'Three character currency code',
),
# SOME FIELDS OMITTED
'payment_fee' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
'default' => 0,
'description' => 'USD transaction fee associated with the payment. payment_gross minus payment_fee equals the amount deposited into the receiver email account. Is empty for non-USD payments. If this amount is negative, it signifies a refund or reversal, and either of those payment statuses can be for the full or partial amount of the original transaction fee. NOTE: This is a deprecated field. Use mc_fee instead.',
),
'payment_gross' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
'default' => 0,
'description' => 'Full USD amount of the customer\'s payment, before transaction fee is subtracted. Will be empty for non-USD payments. This is a legacy field replaced by mc_gross. If this amount is negative, it signifies a refund or reversal, and either of those payment statuses can be for the full or partial amount of the original transaction.',
),
'mc_fee' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Transaction fee associated with the payment. mc_gross minus mc_fee equals the amount deposited into the receiver_email account. Equivalent to payment_fee for USD payments. If this amount is negative, it signifies a refund or reversal, and either of those payment statuses can be for the full or partial amount of the original transaction fee.',
),
'mc_gross' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => ' Full amount of the customer\'s payment, before transaction fee is subtracted. Equivalent to payment_gross for USD payments. If this amount is negative, it signifies a refund or reversal, and either of those payment statuses can be for the full or partial amount of the original transaction.',
),
'settle_amount' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Amount that is deposited into the accounts primary baal nce after a currency conversion from automatic conversion (through your Payment Receiving Preferences) or manual conversion (through manually accepting a payment).',
),
'handling_amount' => array( /* Undocumented IPN Variable */
'description' => 'handling amount',
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
),
'protection_eligibility' => array(
'type' => 'varchar',
'length' => 30,
'description' => 'The protection eligibility of the payment.',
),
'transaction_subject' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'Custom value as passed by you, the merchant. These are passthrough variables that are never presented to your customer',
),
'settle_currency' => array(
'type' => 'varchar',
'length' => 3,
'description' => 'Three character currency code.',
),
'exchange_rate' => array(
'type' => 'numeric',
'precision' => 12,
'scale' => 6,
'description' => 'Exchange rate used if a currency conversion occurred.',
),
# Auctions - NOT SUPPORTED
# Mass Payment - NOT SUPPORTED
# Subscriptions Variables
'txn_type' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'subscr_signup, subscr_cancel, subscr_failed, subscr_payment, subscr_eot, subscr_modify',
),
'subscr_date' => array(
'type' => 'varchar',
'length' => 28,
'description' => 'Start date or cancellation date depending',
),
'subscr_effective' => array(
'type' => 'varchar',
'length' => 28,
'description' => 'Date when the subscription modification will be effective',
),
'period1' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Trial subscription interval in days, weeks, months, years (example: a 4 day interval is period1: 4 D).',
),
'period2' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Trial subscription interval in days, weeks, months, or years.',
),
'period3' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'Regular subscription interval in days, weeks, months, or years.',
),
'amount1' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Amount of payment for trial period 1 for USD payments; otherwise blank (optional).',
),
'amount2' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'A mount of payment for trial period 2 for USD payments; otherwise blank (optional).',
),
'amount3' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Amount of payment for regular subscription period for USD payments; otherwise blank.',
),
'mc_amount1' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Amount of payment for trial period 1, regardless of currency (optional).',
),
'mc_amount2' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Amount of payment for trial period 2, regardless of currency (optional).',
),
'mc_amount3' => array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'description' => 'Amount of payment for regular subscription period, regardless of currency.',
),
'recurring' => array(
'type' => 'int',
'size' => 'tiny',
'description' => 'Indicates whether regular rate recurs (1 is yes, blank is no).',
),
'reattempt' => array(
'type' => 'int',
'size' => 'tiny',
'description' => 'Indicates whether reattempts should occur upon payment failures (1 is yes, blank is no).',
),
'retry_at' => array(
'type' => 'varchar',
'length' => 28,
'description' => 'Date PayPal will retry a failed subscription payment.',
),
'recur_times' => array(
'type' => 'int',
'description' => 'The number of payment installments that will occur at the regular rate.',
),
'subscr_id' => array(
'type' => 'varchar',
'length' => 20,
'description' => 'ID generated by PayPal for the subscriber.',
),
),
'description' => 'Store instant payment notifications from paypal.com',
'indexes' => array(
'txn_id' => array('txn_id'),
),
'primary key' => array('id'),
);
return $schema;
}
/**
* Remove javascript email-hiding kludge.
*/
function lm_paypal_update_6000() {
variable_del('lm_paypal_js_hide_email');
// hook_update_N() no longer returns a $ret array. Instead, return
// nothing or a translated string indicating the update ran successfully.
// See http://drupal.org/node/224333#update_sql.
return t('TODO Add a descriptive string here to show in the UI.') /* array() */;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function lm_paypal_update_6001() {
$ret = array();
// Date field needs to be 28 characters
db_change_field('lm_paypal_ipns', 'payment_date', 'payment_date', array('type' => 'varchar', 'length' => 28));
// hook_update_N() no longer returns a $ret array. Instead, return
// nothing or a translated string indicating the update ran successfully.
// See http://drupal.org/node/224333#update_sql.
return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function lm_paypal_update_6002() {
$ret = array();
// address_status changed to char-40
db_change_field('lm_paypal_ipns', 'address_status', 'address_status', array('type' => 'varchar', 'length' => 40));
// TODO: replace old "int" values with 'confirmed' or 'unconfirmed'. What were they?
// add new field paypal docs
db_add_field('lm_paypal_ipns', 'contact_phone', array('type' => 'varchar', 'length' => 20));
// Add notify_version and IPN text because paypal keep changing formats on us
db_add_field('lm_paypal_ipns', 'notify_version', array('type' => 'varchar', 'length' => 20));
db_add_field('lm_paypal_ipns', 'ipn', array('type' => 'text', 'size' => 'medium'));
// hook_update_N() no longer returns a $ret array. Instead, return
// nothing or a translated string indicating the update ran successfully.
// See http://drupal.org/node/224333#update_sql.
return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
}
/**
* updating fields in lm_paypal_ipns table
* payment_gross
* payment_fee
* adding addtional fields to lm_paypal_ipns table
* handling_amount
* protection_eligibility
* transaction_subject
* ipn_track_id
*/
function lm_paypal_update_7001() {
$spec = array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
'default' => 0,
'description' => 'Full USD amount of the customer\'s payment, before transaction fee is subtracted. Will be empty for non-USD payments. This is a legacy field replaced by mc_gross. If this amount is negative, it signifies a refund or reversal, and either of those payment statuses can be for the full or partial amount of the original transaction.',
);
db_change_field('lm_paypal_ipns', 'payment_gross', 'payment_gross', $spec);
$spec = array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
'default' => 0,
'description' => 'USD transaction fee associated with the payment. payment_gross minus payment_fee equals the amount deposited into the receiver email account. Is empty for non-USD payments. If this amount is negative, it signifies a refund or reversal, and either of those payment statuses can be for the full or partial amount of the original transaction fee. NOTE: This is a deprecated field. Use mc_fee instead.',
);
db_change_field('lm_paypal_ipns', 'payment_fee', 'payment_fee', $spec);
$spec = array( /* Undocumented IPN Variable */
'description' => 'Fi',
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
);
db_add_field('lm_paypal_ipns', 'handling_amount', $spec);
$spec = array( /* Undocumented IPN Variable */
'type' => 'varchar',
'length' => 30,
'description' => 'The protection eligibility of the payment.',
);
db_add_field('lm_paypal_ipns', 'protection_eligibility', $spec);
$spec = array(
'type' => 'varchar',
'length' => 255,
'description' => 'Custom value as passed by you, the merchant. These are passthrough variables that are never presented to your customer',
);
db_add_field('lm_paypal_ipns', 'transaction_subject', $spec);
$spec = array(
'type' => 'text',
'size' => 'medium',
'description' => 'Tracking id',
);
db_add_field('lm_paypal_ipns', 'ipn_track_id', $spec);
}