如何在mangopay中创建钱包?

时间:2013-12-26 08:07:46

标签: php payment-gateway

我想使用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>

2 个答案:

答案 0 :(得分:0)

我不太明白问题是什么 - 您是否尝试在同一页面上创建新用户和钱包?如果是这样,那是不可能的 - 你必须首先获得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

答案 1 :(得分:0)

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;