PayPal IPN无法在我的自定义商店上运行

时间:2017-07-14 00:59:03

标签: php paypal paypal-ipn

我在Sandbox模式下使用PayPal IPN,此代码由于某种原因而无法使用。

我想要发生的是它所说的"经过验证的"做括号之间的事情。但它不是,我不知道任何PhP,但我需要这个为我的钱工作。

这是我的商店的index.php

<head>
    <title>Donation Store | EndersoulsRH</title>
</head>
<body>
    <center>
        <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="text" name="username" placeholder="Your Minecraft Username"> <br>
        <input type="hidden" name="itemname" value="VIP">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="hosted_button_id" value="SHW4WRJBFNDQA">
        <input type="image" src="http://www.endersouls.us/img/buynow.png" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!" width="200px;">
        <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
        </form>

        <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="text" name="username" placeholder="Your Minecraft Username"> <br>
        <input type="hidden" name="itemname" value="VIP">
        <input type="hidden" name="command" value="warp Ranks Hayno">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="hosted_button_id" value="XU8NQN8EVPMYG">
        <input type="image" src="https://www.endersouls.us/img/buynow.png" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!" width="200px">
        <img alt="" border="0" src="https://www.sandbox.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
        </form>

    </center>
</body>
</html>

这是我的paypal ipn.php

<?php
    header('HTTP/1.1 200 OK');

    $resp = 'cmd=_notify-validate';
    foreach ($_POST as $parm => $var) {
        $var = urlencode(stripslashes($var));
        $resp .= "&$parm=$var";
    }

    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
    $record_id = $_POST['custom'];

    $httphead = "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $httphead .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $httphead .= "Content-Length: " . strlen($resp) . "\r\n\r\n";

    $errno ='';
    $errstr='';

    $fh = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

    if (!$fh) {
        die("Connection to and from PayPal has bee lost");
    } else {
        fputs ($fh, $httphead . $resp);

        while (!feof($fh)) {
            $readresp = fgets ($fh, 1024);

            if (strcmp ($readresp, "VERIFIED") == 0) {
                $command = "warp ranks Hayno";

                require_once("WebsenderAPI.php"); // Load Library

                $wsr = new WebsenderAPI("*****","*****","*****"); // HOST , PASSWORD , PORT

                if($wsr->connect()){ //Open Connect

                    $wsr->sendCommand($command);

                }

                $wsr->disconnect(); //Close connection.
            } else if (strcmp ($readresp, "INVALID") == 0) {

            }

        fclose ($fh);
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

我认为您的网址有误。试着把

GetCompetitivePricingForSKU

而不是`$ fh = fsockopen('ssl://www.paypal.com',443,$ errno,$ errstr,30);

在你的测试支付现在按钮也放入sandbox.paypal.com / blahglah`

所以把sandbox.paypal.com .....而不是paypal.com ....

from flask import Flask, render_template, redirect, url_for
import requests
from flask_wtf import FlaskForm
from wtforms import widgets,SelectMultipleField

app = Flask(__name__)
app.config['SECRET_KEY'] = "565&SDdsa7fgSdst7%6"

All_Selected = [('Everything', 'Entire Site')]
Test_Choices = [('10.202.214.196', '#61'), ('10.202.214.197', '#62')]
Test_Choices_NR = [('10.202.214.198', 'Net Relay 1')]


class RebootForm(FlaskForm):
    all_selected = SelectMultipleField('Select All', choices=All_Selected,
                                       option_widget=widgets.CheckboxInput(),
                                       widget=widgets.ListWidget(prefix_label=False))
    available = SelectMultipleField('Available', choices=Test_Choices,
                                    option_widget=widgets.CheckboxInput(),
                                    widget=widgets.ListWidget(prefix_label=False))
    availableNR = SelectMultipleField('Available Net Relays', choices=Test_Choices_NR,
                                      option_widget=widgets.CheckboxInput(),
                                      widget=widgets.ListWidget(prefix_label=False))


@app.route('/form', methods=['GET', 'POST'])
def form():
    form = RebootForm()
    ugly_messages = []
    if form.validate_on_submit():
        ip_addresses = form.available.data
        for ip_address in ip_addresses:
            try:
                requests.get('http://{}/rc.cgi?L=uirreboot.html&c=99'.format(ip_address))
                ugly_messages.append('rebooting {}'.format(ip_address))
                ugly_messages.append('Please wait 30 secs.')
            except Exception:
                ugly_messages.append('{} did not reboot. It may be offline.'.format(ip_address))
        ip_addressesNR = form.availableNR.data
        for ip_addressNR in ip_addressesNR:
            try:
                requests.get('http://{}/setup.cgi?L=uireboot2.html&R'.format(ip_addressNR))
                ugly_messages.append('rebooting {}'.format(ip_addressNR))
                ugly_messages.append('Please wait 30 secs.')
            except Exception:
                ugly_messages.append('{} did not reboot. It may be offline.'.format(ip_addressNR))
        return "<br/>".join(ugly_messages)
    return render_template('form.html', form=form)


if __name__ == '__main__':
    app.run(debug=True)