dqed19166 2015-05-04 08:33
浏览 64
已采纳

带有'min_amount'和'set_customer_limit'的PayPal按钮

I have created a non-hosted PayPal-Button with a text input to let users define an amount to pay. It's a subscription button.

Now the problem is that there must be a minimum amount to pay, say 101 (CHF - Swiss francs).

According to the docs of PayPal HTML-Variables I have the possibility to add the following vars in hidden inputs to my form to get it to work.

  • set_customer_limit with a value of max_limit_own
  • min_amount with a value of 101

The set_customer_limit is working but not the min_amount. Any amount is accepted.

I opened a ticket at the technical support, but no reply till now.

Here's my form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_xclick-subscriptions">
    <!-- //... -->
    <input type="hidden" name="cancel_return" value="mydomain.com/cancel">
    <input type="hidden" name="return" value="mydomain.com/paid">
    <input type="hidden" name="token" value="<?php echo $token; ?>">
    <input type="hidden" name="src" value="1">
    <input type="text" name="a3" value="101.00">
    <input type="hidden" name="p3" value="1">
    <input type="hidden" name="t3" value="Y">
    <input type="hidden" name="currency_code" value="CHF">
    <input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHostedGuest">
<!-- the concerned inputs -->
    <input type="hidden" name="set_customer_limit" value="max_limit_own">
    <input type="hidden" name="min_amount" value="101">
<!-- ---- -->
    <input type="image" src="https://www.paypalobjects.com/de_DE/CH/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
    <img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>

As for the moment, I just validate the minimum amount with JavaScript, which isn't really secure...


EDIT

As an idea, I could implement another form (submit it by AJAX, onchange, onkeyup, whatever), which sets the minimum amount given by the user before the PayPal-form and put it into the PayPal-input then (set to hidden again):

<input type="hidden" name="a3" value="<?php echo $_POST['pre_min_amount'] ?>">

That way I could validate the minimum amount with PhP, before submitting the PayPal-form. But that doesn't seem a clean way to me. Really Glad if anybody could give me a hint!

  • 写回答

1条回答 默认 最新

  • doutan1857 2015-05-05 13:04
    关注

    The answer of the PayPal technical support is: No it is not possible!

    (Date of answering was 05/02/2015) Hopefully, this will be possible in the future. If so please post your answer!


    I'd really suggest using the PayPal API for this kind of thing (including creating a developer account, byting thru the docs, etc).

    So this "solution" is a quick & dirty workaround.


    First, add a small form (I call it the min_amount -form for now) to the page (telling the user, he has to set the amount first):

    <form id="min_amount" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
        <input type="text" id="pre_min_amount" name="pre_min_amount" value="101">
        <input type="submit" value="Set min. Amount">
    </form>
    

    Then, add the whole PayPal form to a PHP variable with NowDoc and add the posted value from the min_amount-form to the a3 input:

    $min_amount = 0;
    $payPalForm = <<<SOME
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <!-- //... -->
        <input type="hidden" name="a3" value="$min_amount">
    </form>
    SOME;
    

    After submitting, check if the minimum amount is true and then only show the PayPal-form:

    if (isset($_POST['pre_min_amount']) && is_numeric($_POST['pre_min_amount']) && floatval($_POST['pre_min_amount']) >= 101) {
        $min_amount = htmlspecialchars($_POST['pre_min_amount']);
        echo $payPalForm;
    }
    

    As I said, it's quick and dirty (no more time for this project), but you ensure to validate the minimum amount on the server-side, not just with Javascript. You could also submit the min_amount-form with an AJAX call, but then the return of this call is on the client-side, which isn't really secure either. (Sure you may also)

    BTW, I am not proud of this solution at all, but sometimes, a programmers life is hard and I'm sure all you coders out there had to do some q&d code somehow, somewhere ;-)...


    Update: 08/05/2015

    All depends on the country in which the concerning account is registered. Full services guaranted by PayPal only in the USA and Canada

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)