-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaypal.php
More file actions
76 lines (66 loc) · 2.05 KB
/
Copy pathpaypal.php
File metadata and controls
76 lines (66 loc) · 2.05 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
<?php
/**
* This file uses the IIF parser to perform some custom IIF modifications
* to the IIF file exported from PayPal. This alse serves as an example.
*/
require 'autoload.php';
use WebuddhaInc\IIF\Parser;
if( !function_exists('inspect') ){
function inspect(){
echo '<pre>' . print_r(func_get_args(), true) . '</pre>';
}
}
if (isset($_FILES['iif']) && isset($_FILES['iif']['tmp_name'])) {
/**
* Parse File
*/
$iif = new Parser();
$iif->readFile( $_FILES['iif']['tmp_name'] );
/**
* Modify Transactions
*/
if ($iif->transactions) {
foreach ($iif->transactions AS &$trans) {
if ($trans->data['CLASS'] == '"General Withdrawal"'){
$trans->splits[0]['ACCNT'] = '"Ask My Accountant"';
}
if ($trans->data['CLASS'] == '"Payment Refund"'){
if ($trans->data['AMOUNT'] > 0) {
$trans->splits[0]['ACCNT'] = '"Computer and Internet Expenses"';
}
else {
$trans->splits[0]['ACCNT'] = '"Sales - Support and Maintenance"';
}
}
if (in_array($trans->data['CLASS'], array('"Reversal of General Account Hold"', '"General Currency Conversion"'))){
$trans->splits[0]['ACCNT'] = '"Computer and Internet Expenses"';
}
foreach ($trans->splits AS &$split) {
if ($split['ACCNT'] == '"Other income"'){
$split['ACCNT'] = '"Sales - Support and Maintenance"';
}
if ($split['ACCNT'] == '"Other expenses"'){
$split['ACCNT'] = '"Computer and Internet Expenses"';
}
if ($split['NAME'] == 'Fee'){
$split['ACCNT'] = '"Merchant Account Fees"';
}
}
}
}
/**
* Download New File
*/
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=" . preg_replace('/^(.*)\.([A-Za-z0-9]+)$/', '$1-Modified.$2', $_FILES['iif']['name']));
$iif->writeFile('php://output');
}
else {
?>
<p>Select a PayPal IIF file to process.</p>
<form method="post" enctype="multipart/form-data">
<input type=file name="iif">
<input type="submit">
</form>
<?php
}