I have developed an API that works fine, but only when I plug in the parameters like "Phone" and "Amount". However, my goal is to pass these parameters from a plugin because those parameters will be different for every user. Below is how am trying to pass the parameters $phone_no and $amount, but its seems that am getting nowhere. Could you please tell me how these parameters can be passed successfully.
//Action Hook to trigger API call add_action('hrw_withdrawal_request_notification','mpesa_request_withdraw');
function mpesa_request_withdraw() {
$user = wp_get_current_user();
// Parameters to pass....
$phone_no = !empty($user->ID) ? get_user_meta($user->ID, 'hrw_phone_number', true) : '';
$amount = isset($_POST['hrw_withdrawal']['amount']) ?
hrw_sanitize_text_field($_POST['hrw_withdrawal']['amount']) : 0;
// API call begins here....
$endPoint = 'https://api.safaricom.co.ke/mpesa/b2c/v1/paymentrequest';
$B2C_ConsumerKey = "tttttttttttttttttttttttttttytr";
$B2C_ConsumerSecret = "gttttttttt";
$AccessToken = GenerateAccessToken($B2C_ConsumerKey, $B2C_ConsumerSecret);
$BusinessShortCode = 30013;
$PhoneNumber = $phone_no;
//$CallBackURL = "https://payments.dllion.store/B2C/callback.php";
$CallBackURL = "https://letawera.specctance.com/B2C/callback.php";
$TimeoutCallBackURL = "https://payments.dllion.store/B2C/callback.php";
$Amount = $amount;
$B2C_Initiator = "DEALLI";
$initiatorSecurityCredential =
Related
Good afternoon,
I'm having trouble with an api POST request - it simply isn't going anywhere, it's not showing on the API log at all - I've got various get requests which work fine but this one just doesn't - I'm unsure what I am doing wrong.
public function broadband_plan(){
$common = array();
$common['main_menu'] = 'Broadband plan';
$cli_or_postcode = isset($_GET["cli_or_postcode"]) ? $_GET["cli_or_postcode"] : "";
$district_id = isset($_GET["district_id"]) ? $_GET["district_id"] : "";
$sub_premises = isset($_GET["sub_premises"]) ? $_GET["sub_premises"] : "";
$premises_name = isset($_GET["premises_name"]) ? $_GET["premises_name"] : "";
$thoroughfare_number = isset($_GET["thoroughfare_number"]) ? $_GET["thoroughfare_number"] : "";
$thoroughfare_name = isset($_GET["thoroughfare_name"]) ? $_GET["thoroughfare_name"] : "";
$locality = isset($_GET["locality"]) ? $_GET["locality"] : "";
$postcode = isset($_GET["postcode"]) ? $_GET["postcode"] : "";
$nad_key = isset($_GET["nad_key"]) ? $_GET["nad_key"] : "";
$post_town = isset($_GET["post_town"]) ? $_GET["post_town"] : "";
$county = isset($_GET["county"]) ? $_GET["county"] : "";
$district_id = isset($_GET["district_id"]) ? $_GET["district_id"] : "";
$request = array();
$request['apiUsername'] = 'XXXXXXX';
$request['apiPassword'] = 'XXXXXXX';
$request['encryption'] = 'SHA-512';
$request['platform'] = 'LIVE';
$request['method'] = 'POST';
$address = '{
"sub_premises": $sub_premises,
"premises_name": $premises_name,
"thoroughfare_number": $thoroughfare_number,
"thoroughfare_name": $thoroughfare_name,
"post_town": $post_town,
"postcode": $postcode,
"district_id": $district_id,
"nad_key": $nad_key
}';
$address = json_encode($address);
$request['url'] = "/broadband/availability" . $address;
$broadband_plan_detail = array();
if (!empty($address)) {
$broadband_plan_detail = $this->get_plan($request);
}
return view('front.broadband_plan',compact('common','broadband_plan_detail'));
}
The $address after $address = json_encode($address); will be an object, it cannot be concatenated as a string in $request['url'] = "/broadband/availability" . $address;
Please check your API URL and ensure you follow their structure, for example if the API URL accept the parameters as GET request, you can pass the parameters likes:
$request['url'] = "/broadband/availability?sub_premises=" . $sub_premises . "&premises_name=" . $premises_name...
Base on your code, the API method is POST, so you might need to prepare the parameters as an array.
I'm trying to make an ethereum raw transaction by php and these libraries:
https://github.com/simplito/elliptic-php
https://github.com/kornrunner/php-keccak
https://github.com/web3p/rlp
this is my code:
use Elliptic\EC;
use kornrunner\Keccak;
use Web3p\RLP\RLP;
$privateKeyHex = '.....'; // wallet private key
$toWallet = '118086be6247fBDa3BC64B4A11F07F3894aA1fAF';
$ec = new EC('secp256k1');
$key = $ec->keyFromPrivate($privateKeyHex );
$publicKeyHex = $key->getPublic('hex');
// $publicKeyHex => 0445e2caf0f227247dfa10440765812492e4d4c9df7b4e74d0d5cd3279fa80f5ef987a70e061ca20c06f09690957c9ba365cf06541181d1291e14c847d0d826583
$nonce= 0;
$gasPrice = 1e9;
$gasLimit = 21000;
$to = hex2bin($toWallet);
$value = 1e14-($gasLimit*$gasPrice)-1;
$inputData = 0;
//*********** EIP_155 *********
$chain_id = 1;
$r = 0;
$s = 0;
//*****************************
$SignData = [$nonce,$gasPrice,$gasLimit,$to,$value,$inputData,$chain_id,$r,$s];
$SignRlpData = rlpEncode($SignData);
$signHash = Keccak::hash(hex2bin($SignRlpData), 256);
$signature = $ec->sign($signHash ,$key);
$r = $signature->r->toString('hex');
$s = $signature->s->toString('hex');
$v = $chain_id*2 + ($signature->recoveryParam +35);
$trxData = [$nonce,$gasPrice,$gasLimit,$to,$value,$inputData,$v,hex2bin($r),hex2bin($s)];
$trxRlpData = rlpEncode($trxData );
// trxRlpData => f86980843b9aca0082520894118086be6247fbda3bc64b4a11f07f3894aa1faf8647d99eefefff8026a08a53214c92ff615c82eede2e51ab9d4d22d6a393f3ab8acee63c23d04e8e2fa7a07661f758f8b968d7597449ce05027edf3f2891fef0d1278f7330e99545109a2b
function rlpEncode($a){
$rlp = new RLP;
$encodedBuffer = $rlp->encode($a);
return $encodedBuffer->toString('hex');
}
now after I send value of $trxRlpData to the ethereum network by https://etherscan.io/pushTx, show me this error message:
Error! Unable to broadcast Tx : {"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"transaction underpriced"}}
but where is problem ?
finally I solved this problem with increasing a little $gasLimit.
$gasLimit = 21001;
When there is a pending transaction and you try to send a new one with same nonce you see this error.
If you needs to make a new transaction while the old one has not confirmed yet, you must get pending transactions count getTransactionCount of address and use as nonce
Anyone know about add new account in LDAP Server with php script?
if i search in google, the answer always this function ldap_add or ldap_mod_add, but that i know the function just add the attributes like ldap_mod_add. i just search php function not ad2ldap or either.
anyone know how to add new account in LDAP Server?
and here my code :
/**
* new release
*/
public static function addNewAccountWithauthForAdmin($user,$attributes=array(),$attributes_val=array(),$user_auth,$password_auth){
$userdata = array();
$userdn = "CN=".$user.",OU=USERS,OU=CORP,DC=domain,DC=corp"; print $userdn;
$user_auth = self::userDomainName($user_auth);
$password_auth = base64_decode($password_auth);
$is_arrayaction = (is_array($attributes) AND is_array($attributes_val)) AND (count($attributes) == count($attributes_val)) ? true : false;
if($is_arrayaction){
$action = array();
for($i=0;$i<count($attributes);$i++){
$userdata[$attributes[$i]] = $attributes_val[$i];
// Output $userdata : {"ipphone":"1825","mail":"nomail#mail.com"}
}
$action[$i] = ldap_mod_add(self::authForChangeAttr($user_auth,$password_auth),$userdn,$userdata);
return $action;
}
$userdata[$attributes] = $attributes_val;
// Output $userdata : {"ipphone":"1825"}
$action = ldap_mod_add(self::authForChangeAttr($user_auth,$password_auth),$userdn,$userdata) ? true : false;
return $action;
}
thanks
ik
ldap_mod_add Allows you to add an attribute to an entry which already exists
ldap_add Allows you to add an entry to the directory
ldap_add requires 3 parameters :
link_identifier : result of the ldap_connect function
dn : The dn of the entry to add
entry : Which is an array representing the entry. It needs to have all the attributes to perform the ldapadd operation (in the LDAP way), ie., you have to set :
The required object classes
["objectClass"]=["Top","person","organizationalPerson","user"];
The mandatory attributes specified by the objectclasses
See this for the objectClass user : https://msdn.microsoft.com/en-us/library/ms683980(v=vs.85).aspx
You can also find a sample code here : https://community.spiceworks.com/topic/458770-adding-users-to-ad-using-php
Try something like this - works for me
$ds = ldap_connect("ldaps://example.org");
if ($ds) {
$r = ldap_bind($ds, "userAdmin", "adminPSW");
$dn = 'CN=username,CN=Users,DC=example,DC=org';
$pwdtxt="password";
## Create Unicode password
$newPassword = "\"" . $pwdtxt . "\"";
$len = strlen($newPassword);
$newPassw = "";
for($i=0;$i<$len;$i++) {
$newPassw .= "{$newPassword{$i}}\000";
}
$ldaprecord['cn'] = "username";
$ldaprecord['mail'] = "mail#example.org";
$ldaprecord['ipphone'] = "0123456789";
ldap_add($ds, $dn, $ldaprecord);
$encodedPass = array('unicodepwd' => $newPassw);
ldap_mod_replace ($ds, $dn, $encodedPass);
}
$res = ldap_error ($ds);
if( $res=="Success"){
##Success
}
ldap_close($ds);
I'm currently working on a project with the MangoPay api (with PHP SDK) and I have some trouble with the PaymentDetails. The function below generate this key (when I call the MangoPay Create method on my PayIn object) :
payins_stdclass-direct_create
instead of :
payins_preauthorized-direct_create
The function I'm using :
<?php
private function createAuthorizationPayIn($authorization, $fees)
{
$payIn = new MangoPay\PayIn();
$payIn->CreditedWalletId = $this->adminWalletId;
$payIn->AuthorId = $this->adminUserId;
$payIn->PaymentType = "PREAUTHORIZED";
$PayIn->PaymentDetails = new MangoPay\PayInPaymentDetailsPreAuthorized();
$payIn->PaymentDetails->PreauthorizationId = $authorization->Id;
$payIn->DebitedFunds = new MangoPay\Money();
$payIn->DebitedFunds->Currency = $authorization->DebitedFunds->Currency;
$payIn->DebitedFunds->Amount = $authorization->DebitedFunds->Amount;
$payIn->CreditedFunds = new MangoPay\Money();
$payIn->CreditedFunds->Currency = $authorization->DebitedFunds->Currency;
$payIn->CreditedFunds->Amount = $authorization->DebitedFunds->Amount;
$payIn->Fees = $fees;
$payIn->ExecutionType = "DIRECT";
$payIn->ExecutionDetails = new MangoPay\PayInExecutionDetailsDirect();
$payIn->ExecutionDetails->SecureMode = "DEFAULT";
$payIn->ExecutionDetails->SecureModeReturnURL = "https://website.com";
$payIn = $this->mangoPayApi->PayIns->Create($payIn);
$authorization->payinId = $payIn->Id;
$authorization = $this->mangoPayApi->CardPreAuthorizations->Update($authorization);
return $payIn;
}
How can I create the right PaymentDetails object to create a preAuthorized PayIn ?
I used paypal php sdk with this :
https://github.com/paypal/merchant-sdk-php/blob/master/samples/RecurringPayments/CreateRecurringPaymentsProfile.php
Express checkout is works well, but use recurring payments have problem : token is invalid.
Line 152 in the sdk, it's said
A timestamped token, the value of which was returned in the response
to the first call to SetExpressCheckout. Call
CreateRecurringPaymentsProfile once for each billing
agreement included in SetExpressCheckout request and use the same
token for each call. Each CreateRecurringPaymentsProfile request
creates a single recurring payments profile.
But i don't understand how to "Call CreateRecurringPaymentsProfile once in SetExpressCheckout", there is my code:
public function createPayToken($returnUrl, $cancelUrl, $payModeData) {
$itemName = $payModeData['name'];
$order = $payModeData['fee'];
// $category = 'Digital';
$category = 'Physical';
$currencyCode = "USD";
$paymentDetails = new PaymentDetailsType();
$itemAmount = new BasicAmountType($currencyCode, $order);
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $itemName;
$itemDetails->Amount = $itemAmount;
$itemDetails->Quantity = 1;
$itemDetails->ItemCategory = $category;
$paymentDetails->OrderTotal = new BasicAmountType($currencyCode, $order);
$paymentDetails->PaymentAction = 'Sale';
$paymentDetails->PaymentDetailsItem[] = $itemDetails;
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[] = $paymentDetails;
$setECReqDetails->ReqConfirmShipping = 0;
$setECReqDetails->NoShipping = 1;
$setECReqDetails->AddressOverride = 0;
$setECReqDetails->CancelURL = $cancelUrl;
$setECReqDetails->ReturnURL = $returnUrl;
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$paypalService = new PayPalAPIInterfaceServiceService();
try {
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
exit;
} catch (Exception $ex) {
echo $ex;
exit;
}
if(isset($setECResponse)) {
if($setECResponse->Ack =='Success') {
$token = $setECResponse->Token;
return $token;
}
var_dump($setECResponse);
exit;
}
return false;
}
Thank you.
You just need to make sure you're including the billing agreement information in your SetExpressCheckout request. Take a look at this sample of set of API calls to complete a recurring payments profile using Express Checkout.
You'll notice the SEC request includes parameters for L_BILLINGTYPE0 AND L_BILLINGAGREEMENTDESCRIPTION0. You need to make sure you include those, otherwise the token that you get back won't be valid for CreateRecurringPaymentsProfile.