我正在开发一个网站,用户必须付费才能使用某些服务。所以我知道PayPal是我可以使用的服务。用户可以使用借记卡,信用卡,PayPal帐户等付款。我知道可以使用PayPal按钮。但在我的网站上,我想给用户一个选项来添加他们选择的数量。用户可以支付5美元或50,000美元或他们想要的任何东西。我不知道我是否可以使用PayPal按钮。
简而言之,用户将以表格形式输入金额。提交表单后,它会将用户重定向到PayPal网站,在那里他们可以支付金额。作为回报,我想确保他们付了多少钱,交易成功与否等来自PayPal,所以我可以在数据库中存储细节,如果交易成功,用户将获得账户余额。
所以我想知道的是PayPal对我来说哪种服务更好?
与PayPal按钮或PayPal网关或PayPal流量网关一样?
答案 0 :(得分:1)
我在我的网站上完成了这个。我会为它发布一些代码。基本上你创建了一个不隐藏的输入表单,称之为金额,因此用户可以输入金额,然后将其传递给paypal。 Paypal网站称它并没有这样做。工作,但确实如此。
我使用的是低端Paypal标准,而不是任何更高级的接口。我有用户添加到购物车然后支付购物车。但你可以为立即购买按钮做同样的事情。使用哪种paypal服务并不重要。如果可以使用基本的PayPal标准,你可以用它们中的任何一个来完成......!
您还可以在交易后从paypal获得用户支付的各个方面。因此,有一个可用于总金额和个别金额的变量,等等。
这是设置捐赠金额以供用户输入的关键:
<input type="hidden" name="button_subtype" value="services">
当然:
<b>Amount $: (Example: nnn.nn)</b>
<input type="text" name="amount">
我不熟悉从paypal回来的变量。对于你想要的东西,贝宝标准应该从我所读过的内容中发挥作用。以下是两种方法,并且都使用paypal标准,因此可以使用任何paypal: 此链接包含以下两个,并提供简要概述: https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/wp_standard_overview/
2) https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/
这是表单的代码体。
<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">
value="https://www.yourwebsite.com/logo.jpg"> -->
<b>Amount $: (Example: nnn.nn)</b>
<input type="text" name="amount">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn /btn_cart_SM.gif" border="0" name="submit">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="yours">
<input type="hidden" name="item_name" value="donation">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="tax" value="0.00">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yours">
<!-- services seems to be the trick -->
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="country" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_paynowCC_LG.gif:NonHosted">
</form>
答案 1 :(得分:1)
我建议使用paypal快速结账。这是一个简单的(PHP)示例:
// Parameters for SetExpressCheckout, which will be sent to PayPal
$padata['L_BILLINGAGREEMENTDESCRIPTION0'] = 'Product description'; $padata['L_BILLINGAGREEMENTDESCRIPTION0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] . ' $'.$product->price.'/month'; $padata['L_PAYMENTREQUEST_0_DESC0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] . ' $'.$product->price.'/month';
$padata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn'; $padata['PAYMENTREQUEST_0_DESC'] = $product->name; $padata['RETURNURL'] = 'http://site_url/paypal/returnurl'; $padata['CANCELURL'] = 'http://site_url/paypal/cancelurl';
$padata['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'; $padata['PAYMENTREQUEST_0_PAYMENTACTION'] = 'SALE'; $padata['PAYMENTREQUEST_0_ITEMAMT'] = $product->price;
$padata['PAYMENTREQUEST_0_AMT'] = $product->price;
$padata['L_BILLINGTYPE0'] = 'RecurringPayments';
$padata['L_PAYMENTREQUEST_0_NAME0'] = $product->name;
$padata['L_PAYMENTREQUEST_0_NUMBER0']= '322';
$padata['L_PAYMENTREQUEST_0_QTY0'] = '1';
$padata['L_PAYMENTREQUEST_0_AMT0'] = $product->price;
$paypal_data = http_build_query($padata); $httpParsedResponseAr = $this->PPHttpPost('SetExpressCheckout', $paypal_data); //Respond according to message we receive from Paypal if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])){ //Redirect user to PayPal store with Token received. $paypalurl ='https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].''; header('Location: '.$paypalurl); }else{ echo 'Error : '.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'';
}
Page returnurl:
$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = 'Recurring Description';
$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] . ' $'.$pr->price.'/month';
$hosteddata['L_PAYMENTREQUEST_0_NAME0'] = $pr->name;
$hosteddata['PROFILEREFERENCE'] = $GetExpressCheckoutDetails['L_PAYMENTREQUEST_0_NUMBER0'];
$hosteddata['PROFILESTARTDATE'] = date('Y-m-d') . 'T' . date('H:i:s').'Z';
$hosteddata['SUBSCRIBERNAME'] = $GetExpressCheckoutDetails['FIRSTNAME'] . ' ' . $GetExpressCheckoutDetails['LASTNAME'];
$hosteddata['TOKEN'] = urlencode($_POST['token']);
$hosteddata['DESC'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'];
$hosteddata['AMT'] = $pr->price;
$hosteddata['BILLINGPERIOD'] = 'Month';
$hosteddata['BILLINGFREQUENCY'] = '1';
$hosteddata['TOTALBILLINGCYCLES'] = '12';
$hosteddata['REGULARTOTALBILLINGCYCLES'] = '1';
$hosteddata['VERSION'] = '74.0';
$hosteddata['MAXFAILEDPAYMENTS'] = '1';
$hosteddata['L_PAYMENTREQUEST_0_QTY0'] = '1';
$hosteddata['L_BILLINGTYPE0'] = 'RecurringPayments';
$hosteddata['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Digital';
$hosteddata['L_PAYMENTREQUEST_0_AMT0'] = $pr->price;
$hosteddata['INITAMT'] = $pr->price;
$hosteddata['L_PAYMENTREQUEST_0_NUMBER0'] = $pr->id;
$hosteddata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn';
$paypal_data = http_build_query($hosteddata); $hosted_saas_response = $this->PPHttpPost('CreateRecurringPaymentsProfile', $paypal_data);
我使用了一个单独的方法将参数发布到paypal
private function PPHttpPost( $methodName_, $nvpStr_ ) {
$api_username = 'yourpaypal@email.com'; $api_password = 'QWEQWEWQEQWEQEQWE';
$api_signature = 'WQEQWEQWEQWEWQEQWEQWEQWEQWEQWE.cT';
$api_endpoint = "https://api-3t.paypal.com/nvp";
$version = '124.0'; $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$api_password&USER=$api_username&SIGNATURE=$api_signature&$nvpStr_";
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
$httpResponse = curl_exec($ch); if(!$httpResponse) { exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
} // Extract the response details. $httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array(); foreach ($httpResponseAr as $i => $value) { $tmpAr = explode("=", $value); if(sizeof($tmpAr) > 1) { $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; } } if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $api_endpoint.");
} return $httpParsedResponseAr;
}