如何在我的网站上显示PayPal购买金额

时间:2016-11-02 18:51:05

标签: javascript php api paypal

我有一个网站,我试图达到1500购买目标并在我的网站上显示进度(如下图所示)。

enter image description here

我的网站上集成了PayPal按钮,我已应用以下代码:

使用Javascript:

using Windows.System.Profile;

IBuffer GetSystemId()
{
  // This sample gets the publisher ID which is the same for all apps
  // by this publisher on this device.
  // Use GetSystemIdForUser if you have the userSystemId capability
  // and need the same ID across all apps for this user (not 
  // really applicable for apps in the Windows Store)
  var systemId = SystemIdentification.GetSystemIdForPublisher();

  // Make sure this device can generate the IDs
  if (systemId.Source != SystemIdentificationSource.None)
  {
    // The Id property has a buffer with the unique ID
    return systemId.Id;
  }

  // This is a very old PC without the correct hardware. Use 
  // another mechanism to generate an ID (or perhaps just give 
  // up due to the small number of people that won't have the ID; 
  // depends on your business needs).
  return GetIdFromAshwidOrSomethingElse();
}

HTML:

<script>
function clickCounter() {
    if(typeof(Storage) !== "undefined") {
        if (localStorage.clickcount) {
            localStorage.clickcount = Number(localStorage.clickcount)+1;
        } else {
            localStorage.clickcount = 1;
        }
        document.getElementById("result").innerHTML = "" + localStorage.clickcount + " <br>Subscribers So Far! And...<br>" + (1500 - +localStorage.clickcount) + "<br>Subscribers To Go" ;
    } else {
        document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
    }
}
clickCounter()
</script>

每次“立即购买”时都会创建一个计数器。单击按钮。问题是计数器在不同的浏览器和设备上重置,因为没有用于维护计数器内存的登录功能。 我想可能集成某种PayPal API命令来从我的PayPal数据中获取结果,但我似乎无法找到有关如何执行此操作的说明/信息。有没有人知道它是否可以使用PayPal API,以及我可以对我现有的代码进行如何更改或更改?

1 个答案:

答案 0 :(得分:0)

我建议使用IPN在新捐款时自动更新您自己的数据库。然后,您可以从自己的数据库中提取图表的数据。

查看PayPal IPN documentation以熟悉它。然后,您可以查看basic sample IPN script PayPal provides

如果您想要更高级的东西,可以在Packagist上使用this library并使用Composer进行安装。

IPN在测试和排除故障方面可能有点棘手,因此我也会在how to test PayPal IPN上查看本指南。