Home >Web Front-end >JS Tutorial >REGISTER WITH PAYPAL TUTORIAL (2/3): A Real Register with PayPal Project
<span>CREATE TABLE IF NOT EXISTS <span>`payment`</span> ( </span><span><span>`payId`</span> int(11) NOT NULL AUTO_INCREMENT, </span><span><span>`timestamp`</span> bigint(20) DEFAULT NULL, </span><span><span>`paid`</span> float DEFAULT NULL COMMENT 'user paid amount returned by paypal', </span><span><span>`bankFee`</span> float DEFAULT NULL, </span><span><span>`currency`</span> varchar(4) DEFAULT NULL, </span><span><span>`txnId`</span> varchar(32) DEFAULT NULL COMMENT 'Transaction ID: specify single unique transaction from paypal. if this field is NOT NULL, means this payment has been process already. So if IPN returns to PHP, we can refuse to update our database.', </span><span><span>`status`</span> varchar(16) DEFAULT NULL, </span><span><span>`uid`</span> int(11) DEFAULT NULL COMMENT 'FK to users PK', </span><span>PRIMARY KEY (<span>`payId`</span>), </span><span>KEY <span>`uid`</span> (<span>`uid`</span>) </span><span>) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; </span><span>CREATE TABLE IF NOT EXISTS <span>`temp_register`</span> ( </span><span><span>`tRegId`</span> int(11) NOT NULL AUTO_INCREMENT, </span><span><span>`fullName`</span> varchar(255) DEFAULT NULL, </span><span><span>`uAcc`</span> varchar(255) DEFAULT NULL, </span><span><span>`uPwd`</span> varchar(32) DEFAULT NULL, </span><span>PRIMARY KEY (<span>`tRegId`</span>) </span><span>) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='prevent unpaid user take uAcc(UNIQUE) in our users table' AUTO_INCREMENT=1 ; </span><span>CREATE TABLE IF NOT EXISTS <span>`users`</span> ( </span><span><span>`uid`</span> int(11) NOT NULL AUTO_INCREMENT, </span><span><span>`fullName`</span> varchar(255) DEFAULT NULL, </span><span><span>`uAcc`</span> varchar(255) NOT NULL, </span><span><span>`uPwd`</span> varchar(32) NOT NULL, </span><span><span>`token`</span> varchar(32) DEFAULT NULL, </span><span><span>`verified`</span> tinyint(1) NOT NULL DEFAULT '0', </span><span><span>`priviledge`</span> enum('delegate','admin','developer') NOT NULL DEFAULT 'delegate', </span><span>PRIMARY KEY (<span>`uid`</span>) </span><span>) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; </span><span>ALTER TABLE <span>`payment`</span> </span><span>ADD CONSTRAINT <span>`payment_ibfk_1`</span> FOREIGN KEY (<span>`uid`</span>) REFERENCES <span>`users`</span> (<span>`uid`</span>);</span>
<span>CREATE TABLE IF NOT EXISTS <span>`payment`</span> ( </span><span><span>`payId`</span> int(11) NOT NULL AUTO_INCREMENT, </span><span><span>`timestamp`</span> bigint(20) DEFAULT NULL, </span><span><span>`paid`</span> float DEFAULT NULL COMMENT 'user paid amount returned by paypal', </span><span><span>`bankFee`</span> float DEFAULT NULL, </span><span><span>`currency`</span> varchar(4) DEFAULT NULL, </span><span><span>`txnId`</span> varchar(32) DEFAULT NULL COMMENT 'Transaction ID: specify single unique transaction from paypal. if this field is NOT NULL, means this payment has been process already. So if IPN returns to PHP, we can refuse to update our database.', </span><span><span>`status`</span> varchar(16) DEFAULT NULL, </span><span><span>`uid`</span> int(11) DEFAULT NULL COMMENT 'FK to users PK', </span><span>PRIMARY KEY (<span>`payId`</span>), </span><span>KEY <span>`uid`</span> (<span>`uid`</span>) </span><span>) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; </span><span>CREATE TABLE IF NOT EXISTS <span>`temp_register`</span> ( </span><span><span>`tRegId`</span> int(11) NOT NULL AUTO_INCREMENT, </span><span><span>`fullName`</span> varchar(255) DEFAULT NULL, </span><span><span>`uAcc`</span> varchar(255) DEFAULT NULL, </span><span><span>`uPwd`</span> varchar(32) DEFAULT NULL, </span><span>PRIMARY KEY (<span>`tRegId`</span>) </span><span>) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='prevent unpaid user take uAcc(UNIQUE) in our users table' AUTO_INCREMENT=1 ; </span><span>CREATE TABLE IF NOT EXISTS <span>`users`</span> ( </span><span><span>`uid`</span> int(11) NOT NULL AUTO_INCREMENT, </span><span><span>`fullName`</span> varchar(255) DEFAULT NULL, </span><span><span>`uAcc`</span> varchar(255) NOT NULL, </span><span><span>`uPwd`</span> varchar(32) NOT NULL, </span><span><span>`token`</span> varchar(32) DEFAULT NULL, </span><span><span>`verified`</span> tinyint(1) NOT NULL DEFAULT '0', </span><span><span>`priviledge`</span> enum('delegate','admin','developer') NOT NULL DEFAULT 'delegate', </span><span>PRIMARY KEY (<span>`uid`</span>) </span><span>) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; </span><span>ALTER TABLE <span>`payment`</span> </span><span>ADD CONSTRAINT <span>`payment_ibfk_1`</span> FOREIGN KEY (<span>`uid`</span>) REFERENCES <span>`users`</span> (<span>`uid`</span>);</span>It is easy to find out that the button is actually a form, so we need to POST data using its inputs. When we generate our ‘register’ button, the redirect URL, should contain ‘&cmd=_s-xclick’ and ‘&hosted_button_id=HA9DZBCKXKCL2’. Now, PayPal Sandbox account has been setup. Then start to code your PDT and IPN handlers.
<span>/** </span><span>* PAYPAL: PDT HANDLER: </span><span>* ==================== </span><span>* called by PayPal, send tokens back </span><span>* get payment details and payment result </span><span>* <span>@return $ret array contains result true/false, and user account or error message </span></span><span>*/ </span><span>private function _PDT() </span><span>{ </span><span>// some indexes can not be missing: </span><span>$ruler = array( </span><span>'tx', // token from paypal </span><span>); </span><span>if(count(array_diff($ruler, array_keys($_GET)))) </span><span>{ </span><span>return array('result' => false, 'error' => 'Index missing ... ', 'index' => $_GET, 'missing' => array_diff($ruler, array_keys($_GET))); </span><span>} </span><span>// read the post from PayPal system and add 'cmd' </span><span>$req = 'cmd=_notify-synch'; </span><span>// get token and prepare request url (send back to paypal) </span><span>$tx_token = $_GET['tx'];$auth_token = "_PJaHiwRfwMmWzW-9nuPuSguYxC-1d9KpxaasaNANtIvyOcmqY6jXNkRmxW"; </span><span>// $auth_token = "OxDenzKmrWPyEXU0YzIg2zs-VAe7ufCADyjbfxF_RpREL4rLEslZrSa21R4"; </span> <span>$req .= "&tx=<span><span>$tx_token</span>&at=<span>$auth_token</span>"</span>; </span> <span>// post back to PayPal system to validate </span> <span>$header = "POST /cgi-bin/webscr HTTP/1.0rn"; </span> <span>$header .= "Host: www.sandbox.paypal.comrn"; </span><span>// $header .= "Host: www.paypal.comrn"; </span> <span>$header .= "Content-Type: application/x-www-form-urlencodedrn"; </span><span>$header .= "Content-Length: " . strlen($req) . "rnrn"; </span> <span>$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); // open socket </span><span>// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // open socket </span> <span>if (!$fp) </span><span>{ </span><span>// HTML FAIL </span><span>return array('result' => false, 'error' => 'HTTP error ... '); </span><span>} </span><span>else </span><span>{ </span><span>fputs ($fp, $header . $req); </span><span>// read the body data </span><span>$res = ''; </span><span>$headerdone = false; </span><span>while (!feof($fp)) </span><span>{ </span><span>$line = fgets ($fp, 1024); </span><span>if (strcmp($line, "rn") == 0) </span><span>{ </span><span>$headerdone = true; // read the header </span><span>} </span><span>else if ($headerdone) </span><span>{ </span><span>$res .= $line; // header has been read. now read the contents </span><span>} </span><span>} </span> <span>// parse the data </span><span>$lines = explode("n", $res); </span><span>$keyarray = array(); </span><span>if (strcmp ($lines[0], "SUCCESS") == 0) </span><span>{ </span><span>for ($i=1; $i_validatePaypal($keyarray); </span><span>} </span><span>// log for manual investigation </span><span>else if (strcmp ($lines[0], "FAIL") == 0) </span><span>{ </span><span>// skipped </span><span>return array('result' => false, 'error' => 'Transaction failed ... '); </span><span>} </span><span>} </span><span>fclose ($fp); </span><span>return $ret; </span><span>}</span>
In the zip file, it contains templates, javascript files, css, bootstrap, jquery, debug plugin and smarty plugin, and all core php source code.
Download Project (344KB)Security is a top priority when setting up a PayPal account. To ensure your account is secure, use a strong, unique password that includes a mix of letters, numbers, and special characters. Also, make sure to provide accurate personal information during registration. PayPal uses this information to verify your identity and protect your account from fraudulent activities.
Yes, you can register for a PayPal account without a credit card. During the registration process, you can choose to link a bank account instead of a credit card. However, linking a credit card can provide additional payment options and security features.
A PayPal business account offers several benefits over a personal account. These include the ability to accept payments from customers, access to business loans and cash advances, and the option to create and send invoices. A business account also allows you to operate under a company or group name.
PayPal is available in more than 200 countries and regions around the world. To register for a PayPal account outside the United States, visit the PayPal website for your specific country or region. The registration process is similar to that in the United States.
When registering for a PayPal account, you will need to provide your legal name, address, phone number, and email address. You will also need to create a password and choose two security questions to help protect your account.
The registration process for a PayPal account is quick and easy. It typically takes just a few minutes to complete. However, it may take a few days for PayPal to verify your bank account or credit card information.
Yes, you can register for more than one PayPal account. However, each account must have a unique email address and financial information. You can have one Personal account and one Business account.
If you forget your PayPal password during registration, you can reset it by clicking on the “Forgot your password?” link on the login page. You will then be prompted to enter your email address, and PayPal will send you an email with instructions on how to reset your password.
Yes, you can change the information you provided during PayPal registration. To do this, log in to your PayPal account, go to your Profile, and select the information you want to change.
No, there is no fee to register for a PayPal account. However, PayPal does charge fees for certain transactions, such as receiving payments for goods and services or sending money to another country.
The above is the detailed content of REGISTER WITH PAYPAL TUTORIAL (2/3): A Real Register with PayPal Project. For more information, please follow other related articles on the PHP Chinese website!