监听器中有多种产品,贝宝IPN

时间:2018-10-26 10:51:25

标签: php post paypal paypal-ipn

我使用贝宝IPN将信息发送到我的php代码,该信息将获取该信息并将附件产品发送给买家电子邮件。

我的问题是,我是否可以在一个侦听器中包含多个产品,或者每个产品都需要单独的文件?

如果两个或两个以上的客户同时购买产品该怎么办? 就像仅将附件发送给其中一个,而不是两个或多个。

<?php
	use PHPMailer\PHPMailer\PHPMailer;
	require "PHPMailer/PHPMailer.php";
	require "PHPMailer/Exception.php";

	if ($_SERVER['REQUEST_METHOD'] != 'POST') {
		header('Location: index.php');
		exit();
	}

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
	$response = curl_exec($ch);
	curl_close($ch);

	if ($response == "VERIFIED" && $_POST['receiver_email'] == "your-email@hotmail.com") {
		$cEmail = $_POST['payer_email'];
		$name = $_POST['first_name'] . " " . $_POST['last_name'];

		$price = $_POST['mc_gross'];
		$currency = $_POST['mc_currency'];
		$item = $_POST['item_number'];
		$paymentStatus = $_POST['payment_status'];

		if ($item == "wordpressPlugin" && $currency == "USD" && $paymentStatus == "Completed" && $price == 67) {
			$mail = new PHPMailer();

			$mail->setFrom("your-email@hotmail.com", "Sales");
			$mail->addAttachment("attachment/wordpress-plugin.zip", "WordPress Plugin");
			$mail->addAddress($cEmail, $name);
			$mail->isHTML(true);
			$mail->Subject = "Your Purchase Details";
			$mail->Body = "
				Hi, <br><br>
				Thank you for purchase. In the attachment you will 
                find product<br><br>
				
				Kind regards.
			";

			$mail->send();
		}
	}

?>

1 个答案:

答案 0 :(得分:0)

不,不会有任何问题。 IPN数据将包含购物车项目数组,因此您可以遍历购物车项目,并对每个项目进行任何操作。

您可能对我们的IPN template感兴趣。现在有点过时了,但是您可以see how we're preparing $cart_items into an array轻松地进行遍历。

dplyr

然后...

$(function() {
  $("#Type").on("change","select", function() {
    var $cat = $("#Category>select");
    $cat.find("option:gt(0)").hide(); // keep first option
    $("." + this.value, $cat).show();
  });
});

该示例准备将数据输入数据库,但是您应该能够将其应用于正在执行的操作。