forked from angelleye/paypal-php-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateInvoice.php
131 lines (116 loc) · 6.26 KB
/
CreateInvoice.php
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
<?php
// Include required library files.
require_once('includes/config.php');
require_once('includes/paypal.class.php');
// Create PayPal object.
$PayPalConfig = array(
'Sandbox' => $sandbox,
'DeveloperAccountEmail' => $developer_account_email,
'ApplicationID' => $application_id,
'DeviceID' => $device_id,
'IPAddress' => $_SERVER['REMOTE_ADDR'],
'APIUsername' => $api_username,
'APIPassword' => $api_password,
'APISignature' => $api_signature,
'APISubject' => $api_subject
);
$PayPal = new PayPal_Adaptive($PayPalConfig);
// Prepare request arrays
$CreateInvoiceFields = array(
'MerchantEmail' => '', // Required. Merchant email address.
'PayerEmail' => '', // Required. Payer email address.
'Number' => '', // Unique ID for the invoice.
'CurrencyCode' => '', // Required. Currency used for all invoice item amounts and totals.
'InvoiceDate' => '', // Date on which the invoice is enabled.
'DueDate' => '', // Date on which the invoice payment is due.
'PaymentTerms' => '', // Required. Terms by which the invoice payment is due. Values are: DueOnReceipt, DueOnSpecified, Net10, Net15, Net30, Net45
'DiscountPercent' => '', // Discount percent applied to the invoice.
'DiscountAmount' => '', // Discount amount applied to the invoice. If DiscountPercent is provided, DiscountAmount is ignored.
'Terms' => '', // General terms for the invoice.
'Note' => '', // Note to the payer company.
'MerchantMemo' => '', // Memo for bookkeeping that is private to the merchant.
'ShippingAmount' => '', // Cost of shipping
'ShippingTaxName' => '', // Name of the applicable tax on the shipping cost.
'ShippingTaxRate' => '', // Rate of the applicable tax on the shipping cost.
'LogoURL' => '' // Complete URL to an external image used as the logo, if any.
);
$BusinessInfo = array(
'FirstName' => '', // First name of the company contact.
'LastName' => '', // Last name of the company contact.
'BusinessName' => '', // Company business name.
'Phone' => '', // Phone number for contacting the company.
'Fax' => '', // Fax number used by the company.
'Website' => '', // Website used by the company.
'Custom' => '' // Custom value to be displayed in the contact information details.
);
$BusinessInfoAddress = array(
'Line1' => '', // Required. First line of address.
'Line2' => '', // Second line of address.
'City' => '', // Required. City of thte address.
'State' => '', // State for the address.
'PostalCode' => '', // Postal code of the address
'CountryCode' => '' // Required. Country code of the address.
);
$BillingInfo = array(
'FirstName' => '', // First name of the company contact.
'LastName' => '', // Last name of the company contact.
'BusinessName' => '', // Company business name.
'Phone' => '', // Phone number for contacting the company.
'Fax' => '', // Fax number used by the company.
'Website' => '', // Website used by the company.
'Custom' => '' // Custom value to be displayed in the contact information details.
);
$BillingInfoAddress = array(
'Line1' => '', // Required. First line of address.
'Line2' => '', // Second line of address.
'City' => '', // Required. City of thte address.
'State' => '', // State for the address.
'PostalCode' => '', // Postal code of the address
'CountryCode' => '' // Required. Country code of the address.
);
$ShippingInfo = array(
'FirstName' => '', // First name of the company contact.
'LastName' => '', // Last name of the company contact.
'BusinessName' => '', // Company business name.
'Phone' => '', // Phone number for contacting the company.
'Fax' => '', // Fax number used by the company.
'Website' => '', // Website used by the company.
'Custom' => '' // Custom value to be displayed in the contact information details.
);
$ShippingInfoAddress = array(
'Line1' => '', // Required. First line of address.
'Line2' => '', // Second line of address.
'City' => '', // Required. City of thte address.
'State' => '', // State for the address.
'PostalCode' => '', // Postal code of the address
'CountryCode' => '' // Required. Country code of the address.
);
// For invoice items you populate a nested array with multiple $InvoiceItem arrays. Normally you'll be looping through cart items to populate the $InvoiceItem
// array and then push it into the $InvoiceItems array at the end of each loop for an entire collection of all items in $InvoiceItems.
$InvoiceItems = array();
$InvoiceItem = array(
'Name' => '', // Required. SKU or name of the item.
'Description' => '', // Item description.
'Date' => '', // Date on which the product or service was provided.
'Quantity' => '', // Required. Item count. Values are: 0 to 10000
'UnitPrice' => '', // Required. Price of the item, in the currency specified by the invoice.
'TaxName' => '', // Name of the applicable tax.
'TaxRate' => '' // Rate of the applicable tax.
);
array_push($InvoiceItems,$InvoiceItem);
$PayPalRequestData = array(
'CreateInvoiceFields' => $CreateInvoiceFields,
'BusinessInfo' => $BusinessInfo,
'BusinessInfoAddress' => $BusinessInfoAddress,
'BillingInfo' => $BillingInfo,
'BillingInfoAddress' => $BillingInfoAddress,
'ShippingInfo' => $ShippingInfo,
'ShippingInfoAddress' => $ShippingInfoAddress,
'InvoiceItems' => $InvoiceItems
);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->CreateInvoice($PayPalRequestData);
// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($PayPalResult);
?>