我正在尝试在我的Codeigniter项目中使用paypal lib https://github.com/jersonandyworks/Paypal-Library-by-RomyBlack。
我能够导航到paypal n支付沙盒上的产品,问题是
以下代码是我的控制器代码。
$this->load->library('paypal');
$config['business'] = 'QD8HYTTSE4M38';
$config['cpp_header_image'] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config['return'] = 'main/viewAds/info.php';
//echo $config['return'];
$config['cancel_return'] = $this->config->base_url() .'main/viewAds/22';
$config['notify_url'] = $this->config->base_url() .'main/viewAds/30';
$config['production'] = FALSE; //Its false by default and will use sandbox
$config["invoice"] = '843843'; //The invoice id
$this->load->library('paypal',$config);
#$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);
$this->paypal->add('T-shirt',1,1); //First item
$this->paypal->pay(); //Proccess the payment
以下是图书馆
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/ ** * CodeIgniter * *适用于PHP 5.1.6或更高版本的开源应用程序开发框架 * * @package CodeIgniter * @author Romaldy Minaya * @copyright版权所有(c)2011,PROTOS。 * @license GLP * @since 1.0版 * @version 1.0 * /
// --------------------------------------------- ---------------------------
/ ** * Paypal类 * * @package CodeIgniter * @subpackage图书馆 * @category付款流程 * @author Romaldy Minaya *
// --------------------------------------------- ---------------------------
文档 此课程允许您根据paypal API进行付款处理, 轻松而轻松。
* 1)使用与paypal page中的变量相同的文档。 * 2)根据需要自定义付款流程。 * 3)用爱建立。
实施
* 1)将此代码复制到控制器的功能
中 $config['business'] = 'demo@demo.com';
$config['cpp_header_image'] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config['return'] = 'sucess.php';
$config['cancel_return'] = 'shopping.php';
$config['notify_url'] = 'process_payment.php'; //IPN Post
$config['production'] = TRUE; //Its false by default and will use sandbox
$config['discount_rate_cart'] = 20; //This means 20% discount
$config["invoice"] = '843843'; //The invoice id
$this->load->library('paypal',$config);
#$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);
$this->paypal->add('T-shirt',2.99,6); //First item
$this->paypal->add('Pants',40); //Second item
$this->paypal->add('Blowse',10,10,'B-199-26'); //Third item with code
$this->paypal->pay(); //Proccess the payment
The notify url is where paypal will POST the information of the payment so you
can save that POST directly into your DB and analize as you want.
With $config["invoice"] is how you identify a bill and you can compare,save or update
that value later on your DB.
For test porpuses i do recommend to save the entire POST into your DB and analize if
its working according to your needs before putting it in production mode. EX.
$received_post = print_r($this->input->post(),TRUE);
//Save that variable and analize.
Note: html reference page http://bit.ly/j4wRR
* / Paypal {
var $config = Array();
var $production_url = 'https://www.paypal.com/cgi-bin/webscr?';
var $sandbox_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?';
var $item = 1;
/**
* Constructor
*
* @param string
* @return void
*/
public function __construct($props = array())
{
$this->__initialize($props);
log_message('debug', "Paypal Class Initialized");
}
// --------------------------------------------------------------------
/**
* initialize Paypal preferences
*
* @access public
* @param array
* @return bool
*/
function __initialize($props = array())
{
#Account information
$config["business"] = 'QD8HYTTSE4M38'; //Account email or id
$config["cmd"] = '_cart'; //Do not modify
$config["production"] = FALSE;
#Custom variable here we send the billing code-->
$config["custom"] = '';
$config["invoice"] = ''; //Code to identify the bill
#API Configuration-->
$config["upload"] = '1'; //Do not modify
$config["currency_code"] = 'USD'; //http://bit.ly/anciiH
$config["disp_tot"] = 'Y';
#Page Layout -->
$config["cpp_header_image"] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config["cpp_cart_border_color"] = '000'; //The HTML hex code for your principal identifying color
$config["no_note"] = 1; //[0,1] 0 show, 1 hide
#Payment Page Information -->
$config["return"] = ''; //The URL to which PayPal redirects buyers’ browser after they complete their payments.
$config["cancel_return"] = ''; //Specify a URL on your website that displays a “Payment Canceled†page.
$config["notify_url"] = ''; //The URL to which PayPal posts information about the payment (IPN)
$config["rm"] = '2'; //Leave this to get payment information
$config["lc"] = 'EN'; //Languaje [EN,ES]
#Shipping and Misc Information -->
$config["shipping"] = '';
$config["shipping2"] = '';
$config["handling"] = '';
$config["tax"] = '';
$config["discount_amount_cart"] = ''; //Discount amount [9.99]
$config["discount_rate_cart"] = ''; //Discount percentage [15]
#Customer Information -->
$config["first_name"] = '';
$config["last_name"] = '';
$config["address1"] = '';
$config["address2"] = '';
$config["city"] = '';
$config["state"] = '';
$config["zip"] = '';
$config["email"] = '';
$config["night_phone_a"] = '';
$config["night_phone_b"] = '';
$config["night_phone_c"] = '';
/*
* Convert array elements into class variables
*/
if (count($props) > 0)
{
foreach ($props as $key => $val)
{
$config[$key] = $val;
}
}
$this->config = $config;
}
// --------------------------------------------------------------------
/**
* Perform payment process
*
* @access public
* @param array
* @return void
*/
function pay(){
#Convert the array to url encode variables
$vars = http_build_query($this->config);
if($this->config['production'] == TRUE){
header('LOCATION:'.$this->production_url.$vars);
}else{
header('LOCATION:'.$this->sandbox_url.$vars);
}
}
// --------------------------------------------------------------------
/**
* Add a product to the list
*
* @access public
* @param array
* @return void
*/
function add($item_name = '',$item_amount = NULL,$item_qty = NULL,$item_number = NULL){
$this->config['item_name_'.$this->item] = $item_name;
$this->config['amount_'.$this->item] = $item_amount;
$this->config['quantity_'.$this->item] = $item_qty;
$this->config['item_number_'.$this->item] = $item_number;
$this->item++;
}
} // END Paypal Class
/ *文件结束Paypal.php / / 位置:./ application / libs / Paypal.php * /
这是我得到的交易页面
我希望它能回到我的网站,但它只会停留在那里。
请告诉我该怎么做。感谢。
答案 0 :(得分:0)
您正在使用的此库显然使用的是PayPal标准版,但不保证用户将返回您的网站。
您可以在PayPal帐户个人资料中启用自动退货,但是,如果用户关闭浏览器或者在重定向发生之前转到其他地方,则他们不会在那里进行。
如果您想确保始终返回PayPal,则需要切换到Express Checkout API,这样可以保证用户最终返回您的网站。我有一个PHP Class Library for PayPal,这对你来说非常简单。这是我继续维护的主要版本,它与Composer一起使用,因此您可以使用它自动加载并使其在CI中可用。
或者,我确实想要使用旧的CI specific version of the library。它现在已经不远了,但我不会像我那样维持它。
无论哪种方式,您都可以使用SetExpressCheckout,GetExpressCheckoutDetails和DoExpressCheckoutPayment。
我还建议你看一下Instant Payment Notification (IPN)。它允许您根据帐户中的交易实时自动执行任务,无论用户是否将其恢复到您的网站。