PayPal Payments Standard is a quick and easy way to integrate Paypal with any website. Normally the method uses a form to send the various details of the transaction to Paypal server.
The below code can simulate the form submission through PHP. With this no form is required. The details of transaction pulled from DB, calculations (if any) done through PHP code and the user can be redirected to Paypal for making the payment.
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; $paypal_id = 'XXXXXXXXXX'; // Paypal Merchant Id $cancel_url = "http://www.domain.com/cancel-return.php"; $return_url = "http://www.domain.com/success-return.php"; $inv = "INV/BVRM/".rand(1111,9999); // Prepare GET data $query = array(); $query['notify_url'] = "http://www.domain.com/ipn.php"; $query['cmd'] = '_xclick'; $query['business'] = $paypal_id; //$query['address_override'] = '1'; $query['first_name'] = "John Doe"; $query['country'] = "IN"; $query['email'] = $_SESSION['email']; $query['amount'] = $product_details['price']; $query['item_name'] = $product_details['name']; $query['currency_code'] = "INR"; $query['custom'] = $_SESSION['user_id'] . "," . $package_price . "," . $package_validity . "," . $package_name; $query['return'] = $return_url; $query['cancel_return'] = $cancel_url; $query['rm'] = "2"; $query['invoice'] = $inv; // Prepare query string $query_string = http_build_query($query); header('location: ' . $paypal_url. "?". $query_string); die();
The array keys are the names of the various fields of the form that is used normally in PayPal Payments Standard method. A detail of all available parameters/fields can be found here