【问题标题】:how to create wallet in mangopay?mangopay如何创建钱包?
【发布时间】:2013-12-26 08:07:45
【问题描述】:

我想使用 php 集成 mangopay,我使用以下链接作为参考: http://docs.mangopay.com/api-references/wallets/ 但我不能这样做,因为如果我使用任何选项,如创建钱包或任何其他选项,那么即使我尝试使用任何其他选项,它也会尝试创建新用户。

以下是我在 mangopay 中创建新钱包的代码:

<h2>Create User</h2>
<form action="https://api.sandbox.mangopay.com/v2/clients" method="post">
<input name="ClientId" id="ClientId" value="<cust's sandbox id>" /><br>
    <input name="Email" id="Email" value="" /><br>
    <input name="FirstName" id="FirstName" value="" /><br>
    <input name="LastName" id="LastName" value="" /><br>
    <input name="Birthday" id="Birthday" value="<?php echo strtotime("1988-03-19");?>" /><br>
    <input name="Nationality" id="Nationality" value="DE" /><br>
    <input name="CountryOfResidence" id="CountryOfResidence" value="DE" /><br>

    <input type="submit" value="submit">
</form>
<h2>Create Wallet</h2>
<form action="https://api.sandbox.mangopay.com/v2/clients" method="post">
    <input name="ClientId" id="ClientId" value="<cust's sandbox id>" /><br>
    <input name="Owners" id="Owners" value="<cust's sandbox id>" /><br>
    <input name="Email" id="Email   " value="mddipen" /><br>
    <input name="Description" id="Description" value="" /><br>
    <input name="Currency" id="Currency" value="EUR" /><br>
    <input type="submit" value="submit">
</form>

【问题讨论】:

  • 你能告诉我如何在 wordpress 中使用 mangopay 吗?
  • @Dipen,您真的应该考虑使用官方 PHP SDK github.com/Mangopay/mangopay2-php-sdk :-) 特别是因为您的代码根本不安全 - 如果您允许用户查看您的 ClientId/Passphrase在他们的浏览器中 - 这些信息非常敏感,只能用于与 Mangopay 的服务器-服务器通信,而不是在您的 HTML 中!

标签: php payment-gateway mangopay


【解决方案1】:
define('MANGOPAY_REQUEST_URL','https://api.sandbox.mangopay.com/v2/');
define('MANGOPAY_ADMIN_ID','Admin ID');
define('CURL_AUTH_HEADER','Authentication Key');

function processCurlJsonrequest($parseUrl, $fieldString) { //Initiate cURL request and send back the result
    $URL=MANGOPAY_REQUEST_URL.$parseUrl;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic ".CURL_AUTH_HEADER, "Content-Type: application/json; charset=utf-8","Accept:application/json, text/javascript, */*; q=0.01"));
    curl_setopt($ch, CURLOPT_URL, $URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fieldString));
    curl_setopt($ch, CURLOPT_POST, 1);

    $resulta = curl_exec($ch);
    if (curl_errno($ch)) {
        print curl_error($ch);
    } else {
        curl_close($ch);
    }
    return $resulta;
}

    $data = array(
        "FirstName" => $first_name,
        "LastName" => $last_name,
        "Address" => "",
        "Birthday" => $birthdatestr, 
        "Nationality" => $nationality,
        "CountryOfResidence" => $CountryOfResidence,
        "Occupation" => "", 
        "IncomeRange" => "", 
        "ProofOfIdentity" => null,
        "ProofOfAddress" => null, 
        //"PersonType" => "NATURAL", 
        "Email" => $email, 
        "Tag" => ""
    );      
    $parseUrl=MANGOPAY_ADMIN_ID.'/users/natural';
    $response= processCurlJsonrequest($parseUrl, $data);
    $arrResponse=json_decode($response);
    $mangopay_userId = $arrResponse->Id;

    $data_mangopay = array(
        "Owners" => array($mangopay_userId),
        "Description" => "A very cool wallet",
        "Currency" => "EUR",
        "Tag" => ""
    );                                                                  
    $parseUrl=MANGOPAY_ADMIN_ID.'/wallets';
    $response_mangopay= processCurlJsonrequest($parseUrl, $data_mangopay);
    $arrResponse_mangopay=json_decode($response_mangopay);
    $mangopay_walletId = $arrResponse_mangopay->Id;

【讨论】:

    【解决方案2】:

    我不太明白问题出在哪里 - 您是否尝试在同一页面上创建新用户和钱包?如果是这样,那是不可能的 - 您必须先获取 UserId,然后才能为钱包创建提供。 另外,如果您还没有使用新的PHP SDK,我建议您这样做,因为它非常全面。但是参考/文档非常糟糕,但我发现 this site 非常有用。

    如果我理解正确,请使用 SDK 解决您的问题:

    //Create an instance of MangoPayApi SDK
    $mangoPayApi = new \MangoPay\MangoPayApi();
    $mangoPayApi->Config->ClientId = MangoPayDemo_ClientId;
    $mangoPayApi->Config->ClientPassword = MangoPayDemo_ClientPassword;
    $mangoPayApi->Config->TemporaryFolder = MangoPayDemo_TemporaryFolder;
    
    //Build the parameters for the request
    $User = new MangoPay\User();
    $User->PersonType = "NATURAL";
    $User->FirstName = "blabla";
    $User->LastName = "blabla";
    $User->Address = "blabla";
    $User->Birthday = 1396886568;
    $User->Nationality = "NZ";
    $User->CountryOfResidence = "ES";
    $User->Email = "hello@example.com";
    
    //Send the request
    $createdUser = $mangoPayApi->Users->Create($User);
    
    //Now for the wallet
    $Wallet = new MangoPay\Wallet();
    $Wallet->Owners = array($createdUser->Id);
    $Wallet->Description = "blabla";
    $Wallet->Currency = "GBP";
    
    //Send the request
    $createdWallet = $mangoPayApi->Wallets->Create($Wallet);
    //store this in your DB: $createdWallet->Id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      相关资源
      最近更新 更多