Coinbase IPN(Webhook)一无所有(空)-PHP

时间:2019-12-06 12:17:42

标签: php json api paypal-ipn coinbase-api

因此,我正在尝试检查付款是否通过coinbase进行了验证。

我有一个工作的前端部分,在该部分中创建了coinbase网站的费用。

P.s。 Coinbase对我的电话的回复在其api文档中看起来像这样:

{
  "data": {
     "id": "f765421f2-1451-fafb-a513-aac6c819fba9",
     "resource": "charge",
    "code": "66BEOV2A",
    "name": "The Sovereign Individual",
    "description": "Mastering the Transition to the Information Age",
    "logo_url": "https://commerce.coinbase.com/charges/ybjknds.png",
    "hosted_url": "https://commerce.coinbase.com/charges/66BEOV2A",
    "created_at": "2017-01-31T20:49:02Z",
    "expires_at": "2017-01-31T21:49:02Z",
    "timeline": [
      {
        "time": "2017-01-31T20:49:02Z",
        "status": "NEW"
      }
    ],
    "metadata": {
      "customer_id": "id_1005",
      "customer_name": "Satoshi Nakamoto"
    },
    "pricing_type": "fixed_price",
    "pricing": {
      "local": { "amount": "100.00", "currency": "USD" },
      "bitcoin": { "amount": "1.00", "currency": "BTC" },
      "ethereum": { "amount": "10.00", "currency": "ETH" }
    },
    "payments": [],
    "addresses": {
      "bitcoin": "mymZkiXhQNd6VWWG7VGSVdDX9bKmviti3U",
      "ethereum": "0x419f91df39951fd4e8acc8f1874b01c0c78ceba6"
    },
    "redirect_url": "https://charge/completed/page",
    "cancel_url": "https://charge/canceled/page",
  }
}

我在其中设置了一个callback_url,当我收到一封确认邮件时,它会在收到电子邮件时起作用。

我想找回交易的详细信息,例如我的自定义元数据,产品名称等。

我的ipn中有这个,但是我收到的电子邮件看起来像这样:

Empty email json response

我的ipn代码是:

$webhookContent = "";
$webhook = fopen('php://input' , 'r');
while (!feof($webhook)) { $webhookContent .= fread($webhook, 4096); }
fclose($webhook);

$data = json_decode($webhookContent);
$email = $data->data->metadata->email;
$orderId = $data->data->id;
$amount = $data->pricing->local->amount;
$custom_id = $data->data->metadata->product_id;

$datePurchased = date('Y-m-d H:i:s');
$feedback_key = randString(10);

mail('myemail@outlook.com', 'Product ID', $custom_id);

如您所见,我想将$ custom_id解析为电子邮件正文。

在前端页面上,我已经发送了这样的元数据:

curl_setopt($ch, CURLOPT_URL, "https://api.commerce.coinbase.com/charges/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
    "name" => "1x $productName",
    "description" => "Bundle",
    "local_price" => array(
        'amount' => "$after_coupon_value",
        'currency' => 'USD'
    ),
    "pricing_type" => "fixed_price",
    "metadata" => array(
        'product_id' => "$product_id",
        'email' => "$clientEmail"
    ),
    "callback_url" => 'example.com/ipn?secret='.$secret
);

Custom_id是产品ID,所以我知道要买的股票,但是从字面上看,我的电子邮件中没有显示该响应,有人可以帮忙吗?

0 个答案:

没有答案