我遇到了一些代码问题。我正在为我的网站制作一个捐赠页面,我不知道如何去展示它的“item_name”部分。我有几种可能的捐赠选项,我想在重定向到付款时显示他们选择在item_name中显示的选项。这就是我所拥有的:
$price = '6.50';
if($_GET['prod'] == 1) //Price for package 1 (Regular Donator)
$price = '6.50';
if($_GET['prod'] == 2) //Price for package 2 (Extreme Donator)
$price = '12.50';
if($_GET['prod'] == 3) //Price for package 3 (10 SoF Spins)
$price = '2.50';
if($_GET['prod'] == 4) //Price for package 4 (20 SoF Spins)
$price = '4.00';
if($_GET['prod'] == 5) //Price for package 5 (Fight Kiln Completion)
$price = '5.50';
if($_GET['prod'] == 6) //Price for package 6 (1 Ragged Gold Key)
$price = '2.00';
if($_GET['prod'] == 7) //Price for package 7 (4 Ragged Gold Keys)
$price = '9.99';
if($_GET['prod'] == 8) //Price for package 8 (12 Ragged Gold Keys)
$price = '20.00';
if($_GET['prod'] == 9) //Price for package 9 (28 Ragged Gold Keys)
$price = '40.00';
$p->add_field('custom', $_GET['username']);
$p->add_field('business', 'dtordik@gmail.com'); //edit to your email
$p->add_field('return', $this_script.'?action=success');
$p->add_field('cancel_return', $this_script.'?action=cancel');
$p->add_field('notify_url', $this_script.'?action=ipn');
$p->add_field('item_name', 'Package '.$_GET['prod']);
$p->add_field('item_number', $_GET['prod']);
$p->add_field('currency_code', 'USD');
$p->add_field('amount', $price);
//$p->add_field('quantity', $_GET['amm']);
$p->add_field('lc', 'GB');
$p->submit_paypal_post(); // submit the fields to paypal
//$p->dump_fields(); // for debugging, output a table of all the fields
break;
您会看到 $ p-> add_field('item_name','Package'。$ _ GET ['prod']); ,它会抓住该号码,然后会显示在paypal网站上作为“包1”我怎样才能做到这一点,如果有人选择'prod'1,它可以成为“常规捐赠者”,“prod”2作为“极端捐赠者”等等。我不知道我是否过度思考,但任何帮助将不胜感激,谢谢!
答案 0 :(得分:0)
这段代码效率有点低,如果优化解决方案就会直截了当。
定义所有产品,价格和标签的清单。
$products = array(
1 => array(
"price" => "6.00",
"label" => "Regular Donator"
),
2 => array(
"price" => "60.00",
"label" => "Extreme Donator"
),
3 => array(
"price" => "0.00",
"label" => "Cheap bastard"
)
);
$product = $_GET["prod"];
$price = $products[$product]["price"];
$label = $products[$product]["label"];
$p->add_field('item_name', $label);
$p->add_field('item_number', $product);
$p->add_field('amount', $price);
// etc