3

Razorpayx 卷曲代码:

curl -u <YOUR_KEY>:<YOUR_SECRET> \-X POST https://api.razorpay.com/v1/contacts \-H "Content-Type: application/json" \-d '{  "name": "Gaurav Kumar",  "email": "gaurav.kumar@example.com",  "contact": "9123456789",  "type": "employee",  "reference_id": "Acme Contact ID 12345",  "notes": {    "note_key": "Beam me up Scotty"  }}'

尝试从 curl-php 实现相同的功能:

$ch = curl_init();

$curlConfig = array(
    CURLOPT_URL            => "https://api.razorpay.com/v1/contacts/",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => array(
        'api-key' => '<KEY>:<SECRET-KEY>'

        ),
    CURLOPT_POSTFIELDS     => array(
        'name' => 'ABCD',
        'email' => "abcd@gmail.com",
        'type' => 'customer'
    )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);

现在出现“请提供您的 api 密钥以进行身份​​验证”的错误。我已经通过 curl 标头传递了密钥;但它会引发错误。请指导如何解决此问题。

4

3 回答 3

4

我有同样的问题。基本上您的 api-key 不会进入标题,而是您必须将其作为用户密码发送。下面的代码运行良好。

    $ch = curl_init();
    $fields = array();
    $fields["name"] = $name;
    $fields["email"] = $email;
    $fields["contact"] = $phone;
    $fields["reference_id"] = "customer".$phone;
    $fields["type"] = "customer";
    curl_setopt($ch, CURLOPT_URL, 'https://api.razorpay.com/v1/contacts');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "api-key: key-secret");
    $headers = array();
    $headers[] = 'Accept: application/json';
    $headers[] = 'Content-Type: application/json';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $data = curl_exec($ch);

    if (empty($data) OR (curl_getinfo($ch, CURLINFO_HTTP_CODE != 200))) {
       $data = FALSE;
    } else {
        return json_decode($data, TRUE);
    }
    curl_close($ch);
于 2019-06-01T13:01:36.617 回答
1

我正在与我的电子商务平台集成,如果它是银行转账和下面的代码,则必须向用户触发一个链接,并且它很有效

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.razorpay.com/v1/payment_links/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n  \"upi_link\": \"true\",\n  \"amount\": 100,\n  \"currency\": \"INR\",\n  \"reference_id\": \"#456\",\n  \"description\": \"Payment for policy no #23456\",\n  \"customer\": {\n    \"name\": \"Gaurav Kumar\",\n    \"contact\": \"+919999999999\",\n    \"email\": \"null\"\n  },\n  \"expire_by\": \"1526282829\",\n  \"notify\": {\n    \"sms\": true\n  },\n  \"reminder_enable\": true,\n  \"notes\": {\n    \"policy_name\": \"Jeevan Bima\"\n  }\n}");
curl_setopt($ch, CURLOPT_USERPWD, '[YOUR_KEY_ID]' . ':' . '[YOUR_KEY_SECRET]');

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

下面的 JSON 应该可以使用您自己的键和值传递

{
  "amount": 1000,
  "currency": "INR",
  "accept_partial": true,
  "first_min_partial_amount": 100,
  "expire_by": 1691097057,
  "reference_id": "TS1989",
  "description": "Payment for policy no #23456",
  "customer": {
    "name": "Gaurav Kumar",
    "contact": "+919999999999",
    "email": "gaurav.kumar@example.com"
  },
  "notify": {
    "sms": true,
    "email": true
  },
  "reminder_enable": true,
  "notes": {
    "policy_name": "Jeevan Bima"
  },
  "callback_url": "https://example-callback-url.com/",
  "callback_method": "get"
}

enter code here

参考 - https://razorpay.com/docs/payment-links/api/new/create/standard/

于 2021-07-09T12:12:27.403 回答
0

下面为我​​工作

$data =http_build_query(
      json_decode('{
    "account_number": "2323230009571676",
    "fund_account_id": "fa_GHf8DVjqbYtAXH",
    "amount": 1000000,
    "currency": "INR",
    "mode": "IMPS",
    "purpose": "refund",
    "queue_if_low_balance": true,
    "reference_id": "Acme Transaction ID 12345",
    "narration": "Acme Corp Fund Transfer",
    "notes": {
    "notes_key_1":"Tea, Earl Grey, Hot",
    "notes_key_2":"Tea, Earl Grey… decaf."
    }
    }',true)
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api.razorpay.com/v1/payouts");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_USERPWD, env('RZP_API_KEY') . ':' . env('RZP_API_SECRETES'));
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output = curl_exec($ch);
    echo $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
于 2020-12-26T12:51:52.503 回答