[英]how to create wallet in mangopay?
I want to integrate mangopay using php and i am using following link as ref: http://docs.mangopay.com/api-references/wallets/ but i can't able to do that because if i am use any options like create wallet or any other then it will try to create new user even i am trying to use any other option.我想使用 php 集成 mangopay,我使用以下链接作为参考: http ://docs.mangopay.com/api-references/wallets/ 但我不能这样做,因为如果我使用任何选项,如创建钱包或任何其他然后它会尝试创建新用户,即使我正在尝试使用任何其他选项。
following is code which i used for create new wallet in mangopay:以下是我用于在 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>
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;
I don't quite understand what the problem is - are you trying to create a new user AND wallet on the same page?我不太明白问题是什么 - 您是否试图在同一页面上创建新用户和钱包? If so, that isn't possible - you'll have to get the UserId first to then supply for the wallet creation.
如果是这样,那是不可能的 - 您必须先获取 UserId,然后才能提供钱包创建。 Also, if you're not yet using the new PHP SDK , I suggest you do as it's really comprehensive.
另外,如果您还没有使用新的PHP SDK ,我建议您使用它,因为它非常全面。 However the reference/docs are pretty dire but I found this site which is very useful.
然而,参考/文档非常糟糕,但我发现这个网站非常有用。
Using the SDK and to solve your problem if I've understood it correctly:如果我理解正确,则使用 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.