Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 11, 2016
0 parents commit 715e3c9
Show file tree
Hide file tree
Showing 34 changed files with 1,738 additions and 0 deletions.
Binary file added 3399.pdf
Binary file not shown.
Binary file added 3400.pdf
Binary file not shown.
Binary file added 9781590597507.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Chapter03/add_to_cart.html
@@ -0,0 +1,14 @@
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
<input type="hidden" name="add" value="1"/>
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="business" value="seller@apress.com"/>
<input type="hidden" name="item_name" value="Cart Item 1"/>
<input type="hidden" name="amount" value="5.00"/>
<input type="hidden" name="no_shipping" value="2"/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="bn" value="PP-ShopCartBF"/>
<input type="hidden" name="shopping_url" value="http://www.myshop.com\products.html"/>
</form>
14 changes: 14 additions & 0 deletions Chapter03/buy_now.html
@@ -0,0 +1,14 @@
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" value="seller@apress.com"/>
<input type="hidden" name="item_name" value="Red Jacket"/>
<input type="hidden" name="item_number" value="7601"/>
<input type="hidden" name="amount" value="125.00"/>
<input type="hidden" name="no_shipping" value="2"/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="bn" value="PP-BuyNowBF"/>
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
</form>

7 changes: 7 additions & 0 deletions Chapter03/cart_upload.html
@@ -0,0 +1,7 @@
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" value="damon@example-business.com"/>
<input type="hidden" name="item_name" value="Shopping Cart total"/>
<input type="hidden" name="amount" value="250.00"/>
<input type="submit" value="PayPal"/>
</form>
12 changes: 12 additions & 0 deletions Chapter03/cart_upload_item_details.html
@@ -0,0 +1,12 @@
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="upload" value="1"/>
<input type="hidden" name="business" value="damon@example-business.com"/>
<input type="hidden" name="item_name_1" value="Item Name 1"/>
<input type="hidden" name="amount_1" value="1.00"/>
<input type="hidden" name="quantity_1" value="1"/>
<input type="hidden" name="item_name_2" value="Item Name 2"/>
<input type="hidden" name="amount_2" value="2.00"/>
<input type="hidden" name="quantity_2" value="3"/>
<input type="submit" value="PayPal"/>
</form>
15 changes: 15 additions & 0 deletions Chapter03/donation.html
@@ -0,0 +1,15 @@
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" value="donations@example-business.com"/>
<input type="hidden" name="item_name" value="School Fundraiser"/>
<input type="hidden" name="item_number" value="2006"/>
<input type="hidden" name="amount" value="50.00"/>
<input type="hidden" name="no_shipping" value="2"/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="tax" value="0"/>
<input type="hidden" name="bn" value="PP-DonationsBF"/>
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
</form>

17 changes: 17 additions & 0 deletions Chapter03/subscription.html
@@ -0,0 +1,17 @@
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
<input type="hidden" name="cmd" value="_xclick-subscriptions"/>
<input type="hidden" name="business" value="test2@test22.com"/>
<input type="hidden" name="item_name" value="Magazine Subscription"/>
<input type="hidden" name="item_number" value="1212"/>
<input type="hidden" name="no_shipping" value="1"/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="bn" value="PP-SubscriptionsBF"/>
<input type="hidden" name="a3" value="20.00"/>
<input type="hidden" name="p3" value="10"/>
<input type="hidden" name="t3" value="W"/>
<input type="hidden" name="src" value="1"/>
<input type="hidden" name="sra" value="1"/>
</form>
48 changes: 48 additions & 0 deletions Chapter04/Config.php
@@ -0,0 +1,48 @@
<?php

class PayPal_EncryptedButtons_Config {
// {{{ properties
/****************************************
*
* Please edit the options below to reflect
* your system configuration. If they are
* incorrect, this program may not work as
* expected.
*
****************************************/
/* Certificate ID */
var $cert_id = "PZ9MJJTPW9NP8";
/* PayPal E-mail Address */
var $business = "seller@testaccount.com";
/* Receiver E-Mail - E-Mail Address Payment will be sent to */
/* Leave blank if the same as above */
var $receiver = "";
/* Base Directory - Base directory where all files will be stored */
/* This should be outside the website root, and only readable by you */
/* The trailing slash is REQUIRED */
var $basedir = "/var/www/php_paypal/";
/* Certificate Store - Directory in which all certificates are stored */
/* Can be the name of a subdirectory under basedir, or another path */
/* The trailing slash is REQUIRED */
var $certstore = "certificates/";
/* Temporary Directory - Where temporary files are stored regarding å
the transaction. This should be under the base directory OR outside å
the webroot, and only readable by you/the web server. Files from this å
directory are automatically removed after use. The trailing slash is REQUIRED */
var $tempdir = "/var/www/php_paypal/temp/";
/* OpenSSL Path - Path to the OpenSSL Binary */
/* If openssl isn't in your PATH, then change this to where å
it's located, otherwise leave it as it is */
/* No trailing slash */
var $openssl = "openssl";
/* Certificate Names - Names of all the certificates required */
/* Your Private Key Filename */
var $my_private = "/var/www/php_paypal/certificates/cert_key.pem";
/* Your Public Certificate Filename */
var $my_public = "/var/www/php_paypal/certificates/cert_key.pem";
/* PayPal's Public Certificate Filename */
var $paypal_public = "/var/www/php_paypal/certificates/paypal_public_cert.pem";
// }}}
}
?>

62 changes: 62 additions & 0 deletions Chapter04/CreateButton.java
@@ -0,0 +1,62 @@
package com.apress.paypal;

import java.util.Properties;
import java.util.Enumeration;
import com.paypal.sdk.profiles.EWPProfile;
import com.paypal.sdk.profiles.ProfileFactory;
import com.paypal.sdk.services.EWPServices;
import com.paypal.sdk.exceptions.PayPalException;

public class CreateButton {

// the button properties
public static final String PROPERTIES_FILE = "button.params.properties";
// path to your PKCS12 file
public static final String PKCS12 = "./my_pkcs12.p12";
// path to PayPal's public certificate
public static final String PAYPAL_CERT = "./paypal_cert_pem.txt";
// use https://www.sandbox.paypal.com if testing
public static final String URL = "https://www.paypal.com";


public static void main (String args[]) {
// Check to see if the user provided a password
if (args.length != 1) {
System.out.println("You must provide a password.");
System.exit(0);
}
// password used to encrypt your PKCS12 files
// obtained from the command line
String USER_PASSWORD = args[0];
// Read properties file with a custom loader
PropertiesLoader loader = new PropertiesLoader(); // custom loader
Properties properties = loader.loadProperties(PROPERTIES_FILE);
// First we will create the EWPProfile object
try {
EWPProfile ewpProfile = ProfileFactory.createEWPProfile();
ewpProfile.setCertificateFile(PKCS12);
ewpProfile.setPayPalCertificateFile(PAYPAL_CERT);
ewpProfile.setPrivateKeyPassword(USER_PASSWORD);
ewpProfile.setUrl(URL);
StringBuilder buttonParameters = new StringBuilder();
// Now we will define the button parameters for our payment button
for (Enumeration e = properties.keys(); e.hasMoreElements();) {
String key = (String)e.nextElement();
buttonParameters.append(key + "=" + properties.getProperty(key) + "\n");
}
// Next we will create the EWPServices object
// and tell it which EWPProfile object to use
EWPServices ewpServices = new EWPServices();
ewpServices.setEWPProfile(ewpProfile);
// Finally we are ready to call the method to perform the button encryption
String encryptedButton =
ewpServices.encryptButton(buttonParameters.toString().getBytes());
System.out.println(encryptedButton);
}
catch (PayPalException ppe) {
System.out.println("An exception occurred when creating the button.");
ppe.printStackTrace();
}
}
}

197 changes: 197 additions & 0 deletions Chapter04/EncryptedButtons.php
@@ -0,0 +1,197 @@
<?php
// {{{ constants
// {{{ error codes
define("PP_ERROR_OK", 0);
define("PP_ERROR_FILE", 1);
define("PP_ERROR_OPENSSL", 2);
define("PP_ERROR_DATA", 3);
define("PP_ERROR_PARAMS", 4);
define("PP_ERROR_NOTFOUND", 5);
define("PP_ERROR_UNKNOWN", 6);
// }}}
// }}}
require_once "Config.php";
class PayPal_EncryptedButtons {
// {{{ properties
/** Button Data Array */
var $buttonData = array();
/** Config Pointer */
var $config;
/** Internal Data Handler */
var $_data;
/** Random Transaction ID */
var $_rnd;
var $debug = true;
// }}}
// {{{ constructor
/**
* Constructs a new PayPal_EncryptedButtons object
*
* @access public
*/
function PayPal_EncryptedButtons($config = array()) {
$this->config = new PayPal_EncryptedButtons_Config;
return;
}
// }}}
// {{{ changeConfig()
/**
* Change a Configuration Directive after the class has been loaded
*
* @param string $name
* @param string $value
* @return bool
* @access public
*
*/
function changeConfig($name, $value = "") {
if ($this->config->$name) {
$this->config->$name = $value;
return true;
}
else {
return false;
}
}
// }}}
// {{{ addButtonParam()
/**
* Add parameters to the button code
*
* @param mixed $names
* @param mixed $values
* @return int
* @access public
*/
function addButtonParam($names = "", $values = "") {
if ((is_array($names) && !is_array($values)) || (!is_array($names) && is_array($values))) {
return PP_ERROR_PARAMS;
}
elseif (is_array($names) && is_array($values)) {
if (count($names) !== count($values)) {
return PP_ERROR_PARAMS;
}
$i = 0;
while ($i < count($names)) {
$this->buttonData[$names[$i]] = $values[$i];
$i++;
}
return PP_ERROR_OK;
}
else {
if ($names == "" || $values == "") {
return PP_ERROR_PARAMS;
}
else {
$this->buttonData[$names] = $values;
return PP_ERROR_OK;
}
}
}
// }}}
// {{{ delButtonParam()
/**
* Deletes a Button Parameter
*
* @param string $name
* @return int
* @access public
*/
function delButtonParam($name = "") {
if ($name == "") {
return PP_ERROR_PARAMS;
}
if ($this->buttonData[$name] !== null) {
$this->buttonData[$name] = null;
return PP_ERROR_OK;
}
return PP_ERROR_NOTFOUND + 10;
}
// }}}
// {{{ encryptButtonData()
/**
* Encrypts the data in buttonData
*
* @return int
* @access public
*/
function encryptButtonData() {
$this->encryptedButton = null;
if (!is_dir($this->config->basedir)) {
if (!mkdir($this->config->basedir)) {
return PP_ERROR_NOTFOUND + 20;
}
}
@chdir($this->config->basedir);
$this->_data = "cmd=_xclick\n";
$this->_data .= "business=".$this->config->business."\n";
$this->_data .= "receiver_email=".$this->config->receiver_email."\n";
foreach ($this->buttonData as $name => $val) {
if ($val == null) { continue; }
$this->_data .= $name."=".$val."\n";
}
$this->_data .= "cert_id=".$this->config->cert_id;
$this->_rnd = rand(100000, 999999);
if (!is_dir($this->config->tempdir)) {
if (!@mkdir($this->config->tempdir)) {
return PP_ERROR_NOTFOUND + 30;
}
}
$f = @fopen($this->config->tempdir.$this->_rnd.".1", "w");
//if (!$f) { return PP_ERROR_FILE; }
if (!$f) { return 41; }
fwrite($f, trim($this->_data), strlen(trim($this->_data)));
fclose($f);
if (!file_exists($this->config->my_private)) {
return 145;
}
if (!file_exists($this->config->my_public)) {
return 245;
}
if (!file_exists($this->config->paypal_public)) {
return 345;
}
if (!file_exists($this->config->my_private) ||
!file_exists($this->config->my_public) ||
!file_exists($this->config->paypal_public)) {
return PP_ERROR_NOTFOUND + 40;
}
$exec = $this->config->openssl." smime -sign -in ".$this->config->
tempdir.$this->_rnd.".1 -signer ".$this->config->my_public." -inkey ".$this->
config->my_private." -outform der -nodetach -binary > ".$this->config->
tempdir.$this->_rnd.".2";
$status1 = `$exec`;
$exec = $this->config->openssl." smime -encrypt -des3 -binary -outform pem ".$this->config->paypal_public." < ".$this->config->
tempdir.$this->_rnd.".2 > ".$this->config->tempdir.$this->_rnd.".3";
$status2 = `$exec`;
$this->encryptedButton = trim(file_get_contents($this->config->tempdir.$this->_rnd.".3"));
@unlink($this->config->tempdir.$this->_rnd.".1");
@unlink($this->config->tempdir.$this->_rnd.".2");
@unlink($this->config->tempdir.$this->_rnd.".3");
if (strpos($status1, "No such file or directory") !== false || strpos($status2, "No such file or directory") !== false) {
return PP_ERROR_OPENSSL;
}
if (!$this->encryptedButton) {
return PP_ERROR_DATA;
}
return PP_ERROR_OK;
}
// }}}
// {{{ getButton()
/**
* Returns the Encrypted Button Contents
*
* @return string
* @access public
*/
function getButton() {
if (!$this->encryptedButton) {
return "";
}
return $this->encryptedButton;
}
// }}}
}
// }}}
?>

0 comments on commit 715e3c9

Please sign in to comment.