DoDirectPayment Examples
Notes
Request
// Create instance of the phpPayPal class $paypal = new phpPayPal(); // (required) $paypal->ip_address = $_SERVER['REMOTE_ADDR']; // Order Totals (amount_total is required) $paypal->amount_total = '56.48'; $paypal->amount_shipping = '5.99'; // Credit Card Information (required) $paypal->credit_card_number = '1234123412341234'; $paypal->credit_card_type = 'Visa'; $paypal->cvv2_code = '123'; $paypal->expire_date = '112008'; // Billing Details (required) $paypal->first_name = 'John'; $paypal->last_name = 'Doe'; $paypal->address1 = '123 Maple Street'; $paypal->address2 = 'Apt 3'; $paypal->city = 'Middletown'; $paypal->state = 'TX'; $paypal->postal_code = '77570'; $paypal->phone_number = '8315555555'; $paypal->country_code = 'US'; // Shipping Details (NOT required) $paypal->email = 'johndoe@example.com'; $paypal->shipping_name = 'John Doe'; $paypal->shipping_address1 = '123 Maple Street'; $paypal->shipping_address2 = 'Apt 3'; $paypal->shipping_city = 'Middletown'; $paypal->shipping_state = 'TX'; $paypal->shipping_postal_code = '77570'; $paypal->shipping_phone_number = '8315555555'; $paypal->shipping_country_code = 'US'; // Add Order Items (NOT required) - Name, Number, Qty, Tax, Amt // Repeat for each item needing to be added $paypal->addItem('Item Name', 'Item Number 012', 1, 0, '50.49'); // Perform the payment $paypal->DoDirectPayment();
For more information on field descriptions, requirements and corresponding PayPal fields, see the parameters list.
Required Fields
payment_action- Default is set to Sale, not need to reset it unless differentip_addressamount_totalcredit_card_type- Visa, MasterCard, Discover, Amexcredit_card_numberexpire_date-MMYYYYformatcvv2_code- May not be required, see parameters listfirst_namelast_name
Optional Fields
emailaddress1address2citystatepostal_codephone_numbercountry_code- default is 'US'notify_urlcurrency_codeamount_itemsamount_shippingamount_handlingamount_taxdescriptioncustominvoice_number- Shipping Address
shipping_nameshipping_address1shipping_address2shipping_cityshipping_stateshipping_postal_codeshipping_country_codeshipping_phone_number
Response
The class instance will always provide the raw PayPal response to the Response array. During testing (sandbox mode), you can simply output the value of Response to see the PayPal response.
$paypal->Response; // Display the response print_r($paypal->Response);
If the DoDirectPayment method was successful, the _error variable will be set to false. This includes a Success With Warning response from PayPal. Otherwise, if there was an exception (read: failure), this will be set to true.
Success Response
If the transaction was successful, PayPal will return the following values:
amount_totalavs_codecvv2_matchtransaction_id
For AVS and CVV2 Response codes, see the PayPal Integration Center Direct Payment information towards the bottom of the link.
Error Response
If there was an exception with the interaction with PayPal, _error will return true.
See the error documentation for details about error return values and procedures.