$data = [
"key" => $api_key,
"amount" => $amount,
"name" => "DJ Tiesto",
"description" => "Tron Legacy",
"image" => "logo.png",
"prefill" => [
"name" => "Daft Punk",
"email" => "customer#merchant.com",
"contact" => "9999999999",
],
"notes" => [
"address" => "Hello World",
"merchant_order_id" => "12312321",
],
"theme" => [
"color" => "#F37254"
],
"order_id" => $razorpayOrderId,
];
I am trying to integrate razorpay with php everything is ok but in prefill, I get a default value. how can I change this value to custom value?
In prefill you will get the value which you are given in the prefill object. Just like you passsed $amount and $razorpayOrderId you can use $name and $email etc which might be the value you get from textbox or something like that. Store those names and email in a variable and pass that into prefill.
you can easily change the default value by fetching those values from database or pass those values through ulr parameters as i have done in php.
get order id through url parameter or post request
$orderid = $_GET['orderid'];
run php mysql query to fetch data from database based on order id(i
have used 2 table one for payment details and another one for
userdetails)
$query = "SELECT ud.Name, ud.lname,
ud.MobileId,ud.EmailID,opd.pay_amount, opd.receipt, opd.transaction_id
FROM online_payment_details as opd
INNER JOIN userdetails as ud
ON opd.user_id=ud.UserID
WHERE order_id='$orderid';";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$name = $row['Name'].' '.$row['lname'];
$razorpayOrderId = $orderid;
$amount_pay = $row['pay_amount'];
$receipt = $row['receipt'];
$transaction_id = $row['transaction_id'];
$displayAmount = $amount_pay ;
$corporateName = '';
$email = $row['EmailID'];
$contact = $row['MobileId'];
now in your data array add above variables in data array
$data = [
"key" => $keyId,
"amount" => $amount_pay,
"name" => $name,
"description" => "",
"image" => "",
"prefill" => [
"name" => $corporateName,
"email" => $email,
"contact" => $contact,
],
"notes" => [
"address" => "Hello World",
"merchant_order_id" => $transaction_id,
],
"theme" => [
"color" => "#F37254"
],
"order_id" => $razorpayOrderId,
"receipt" => $receipt,
];
and now in checkout/automatic page in block fetch values from
data array and store in data attribute as below
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="<?php echo $data['key']?>"
data-amount="<?php echo $data['amount']?>"
data-currency="INR"
data-name="<?php echo $data['name']?>"
data-image="<?php echo $data['image']?>"
data-description="<?php echo $data['description']?>"
data-prefill.name="<?php echo $data['prefill']['name']?>"
data-prefill.email="<?php echo $data['prefill']['email']?>"
data-prefill.contact="<?php echo $data['prefill']['contact']?>"
data-notes.shopping_order_id="<?php echo $data['receipt']?>"
data-order_id="<?php echo $data['order_id']?>"
<?php if ($displayCurrency !== 'INR') { ?> data-display_amount="<?php echo $data['display_amount']?>" <?php } ?>
<?php if ($displayCurrency !== 'INR') { ?> data-display_currency="<?php echo $data['display_currency']?>" <?php } ?>
>
</script>
Related
<?php
$allBookings = [
"IMD002" => [
"client" => "James Holden",
"paid" => "yes",
"email" => "james.holden#gmail.com"
],
"IMD003" => [
"client" => "Harold P. Redman",
"paid" => "yes",
"email" => "HaroldPRedman#dayrep.com"
],
"IMD004" => [
"client" => "Marcus C. Nelson",
"paid" => "no",
"email" => "MarcusCNelson#armyspy.com"
]
];
// DONT EDIT ANYTHING BELOW HERE
if(!empty($_POST)) {
$clientName = $booking['client'];
}
else {
$clientName = null;
};
?>
<!-- DONT EDIT ANYTHING BELOW HERE -->
<div class="myApp">
<form method="post">
<input type="text" name="bookingReference" placeholder="Booking Reference">
<input type="submit" value="Find Client">
</form>
<h2 id="result_name">Client name: <em><?php echo $clientName; ?></em></h2>
</div>
How can I showup the credentials when I type into the input field (booking reference) for example "IMD002"? As it should show up the array listed in php under "IMD002". I'm assuming its something to do with a $_POST statement?
Thanks alot
After $allBookings = [ ... ]
Try adding something like :
if(isset($_POST['bookingReference']) &&
isset($allBookings[$_POST['bookingReference']])) {
$booking = $allBookings[$_POST['bookingReference']];
}
else {
$booking = ['client' => 'Invalid Ref/Not found'];
};
To search, Use $_POST['bookingReference'] as index to, $allBookings, your data array;
Try:
$allBookings[$_POST['bookingReference']];
Print the content:
print_r( $allBookings[$_POST['bookingReference']] );
I want to dynamically create a short array with a list of objects. This is for a POST request with the Guzzle client. That's why I need it in a short array.
example of a Guzzle post request:
$res = $this->client->request($methode, $request_url, [
'form_params' => [
'param' => 'value'
]
]);
Problem case:
I have got a List: Params of Objects: Param.
Param has three attributes id, name, link_id.
Let's say the List has three Object.
param(1, email, 1)
param(2, username, 1)
param(3, password, 1)
I want to dynamically create from the list an array with the short array syntax.
Example(Pseudo):
for each params as param
[
'form_params' => [
param->name => 'value'
]
]
the result of this code will be like this
[
'form_params' => [
'email' => 'value',
'username' => 'value',
'password' => 'value'
]
]
Code example:
$params = array(
"param" => array (
"id" => "1",
"name" => "username",
"link_id" => "1",
)
);
$value = '';
$shortarray = '';
foreach($params as $key => $param){
$shortarray .= $param->name . '=>' . $value . ',';
}
$postParams = ['form_params' => [ . $shortarray . ]];
I really could use some help. Thank you in advance.
If you want to just show short array syntax than this solution may helps you to resolve you problem.
https://stackoverflow.com/a/35207172/4781882
I am not quite sure why you require it be a "short array", but here's a solution...
I assume this is a web form, yes?
So let's assume you name your forms in a way that is usable, like:
<form method="POST" action="yourform.html">
Line 1 <input name="email1"> | <input name="user1"> | <input name="password1">
<br/>-------<br/>
Line 2 <input name="email2"> | <input name="user2"> | <input name="password2">
<br/>-------<br/>
Line 3 <input name="email3"> | <input name="user3"> | <input name="password3">
</form>
Then...
for($i = 1; $i <= 3; $i++ {
$postparms[] = ['email' => $_POST['email'.$i], 'user' => $_POST['user'.$i], 'password' => $_POST['password'.$i] ];
}
print_r($postparms);
I am trying to get multidimensional array out of query and for some reasons it does not work.
I use query to retrieve data from mysql.
$sql = "SELECT Id, UserID, TimeAction, Command FROM users_checked WHERE UserId = 4 AND date(TimeAction) = '2016-12-05 '";
$q=$conn->query($sql);
$data = array();
while($r=$q->fetchAll((PDO::FETCH_ASSOC))){
$data[]=$r;
}
Array output
I should get array like printed below
$data = array(
array(
"Id" => "1",
"UserID" => "1",
"TimeAction" => "2016-11-29 08:00:00",
"Command" => "Prijava"
),
array(
"ID" => "1",
"USERID" => "1",
"TimeAction" => "2016-11-29 10:05:14",
"Command" => "Odjava"
),
array(
"Id" => "1",
"UserID" => "1",
"TimeAction" => "2016-11-29 12:22:14",
"Command" => "PoslovniIzlazak"
),
array(
"ID" => "1",
"USERID" => "1",
"TimeAction" => "2016-11-29 13:32:14",
"Command" => "Prijava"
),
array(
"ID" => "1",
"USERID" => "1",
"TimeAction" => "2016-11-29 16:00:00",
"Command" => "Odjava"
),
);
fetchAll - Returns an array containing all of the result set rows where as fetch - Fetches the next row from a result set.
So you have to use fetch instead of fetchAll if you want the data row wise.
Try this code.
while ($r = $q->fetch(PDO::FETCH_ASSOC))
{
$data[] = $r;
}
Reference:
fetch
fetchAll
You should probably use fetch_assoc() instead of fetch_all in your for loop, this way you can push the data you want into your array for each row of your mysql query result.
It would look like this :
$data = array();
while ($row = $r->fetch_assoc()) {
$row_array = array(
"Id" => row['Id'],
"UsedID" => row['UserID'],
"TimeAction" => row['TimeAction'],
"Command" => row['Command']
);
array_push($data, $row_array);
}
Please note I didn't test the code, I'm doing this by head.
Also, I'm guessing you didn't mean to write all Ids to "1" in your example.
So I'm back again. My problem is this:
I have an array of Docusign Templates from checkboxes in a Codeigniter view:
<?php
echo form_open('create_envelope');
foreach ($response["envelopeTemplates"] as $envelopeTemplate) { ?>
<li><?php echo form_checkbox('templatearray[]', $envelopeTemplate["templateId"], FALSE), $envelopeTemplate["name"]; ?></li>
<?php } ?>
What I'm trying to do is add the templates to our REST Header request:
$data = array(
"accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"templateId" => "ID from template array here",
"templateRoles" => array(
array(
"tabs" => array(
"textTabs" => array (
array (
"tabLabel" => "lic_num",
"value" => "$license_number"
),
array (
"tabLabel" => "ubi_num",
"value" => "$ubi_number"
),
array (
"tabLabel" => "tra_nam",
"value" => "$trade_name"
)
)
),
"email" => "$applicant_email",
"name" => "$applicant_name",
"roleName" => "Applicant"
)
),
"status" => "sent"
);
Is this possible?
EDIT: So I got it to work using loops to get my data in the request, but I'm running into an interesting problem. If I put one or two templates in the envelope, it sends fine. If I put more than two in, it duplicates the templates. Here is my code for the complicated loops:
$compTempArray = array();
$applicant_name = $this->input->post("applicant_name");
$applicant_email = $this->input->post("applicant_email");
$license_number = $this->input->post("license_number");
$ubi_number = $this->input->post("ubi_number");
$trade_name = $this->input->post("trade_name");
foreach($hello as $key => $value) {
if(sizeof($hello) > 1) {
for($i = 1; $i < sizeof($hello); $i++) {
$compTempArray[] = array("serverTemplates" => array(
array(
"sequence" => $i,
"templateId" => $value
)
),
"inlineTemplates" => array(
array(
"sequence" => $i,
"recipients" => array(
"signers" => array(
array(
"tabs" => array(
"textTabs" => array (
array ("tabLabel" => "lic_num", "value" => $license_number),
array ("tabLabel" => "ubi_num", "value" => $ubi_number),
array ("tabLabel" => "tra_nam", "value" => $trade_name)
)
),
"email" => "*********#*****.com",
"name" => $applicant_name,
"recipientId" => "1",
"roleName" => "Applicant"
),
)
)
)
));
}
$data = array("accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"compositeTemplates" => $compTempArray,
"status" => "sent");
} else {
$data = array("accountId" => $accountId,
"emailSubject" => "Hello World!",
"emailBlurb" => "This comes from PHP",
"templateId" => "$value",
"templateRoles" => array(
array(
"tabs" => array(
"textTabs" => array (
array ("tabLabel" => "lic_num", "value" => $license_number),
array ("tabLabel" => "ubi_num", "value" => $ubi_number),
array ("tabLabel" => "tra_nam", "value" => $trade_name)
)
),
"email" => "*********#*****.com",
"name" => $applicant_name,
"roleName" => "Applicant"
)
),
"status" => "sent");
}
}
Any idea why it would do this?
NEW EDIT: Update on this weirdness: one to two - one copy of each template, three - it doubles the amount of each template, four - it triples the amount, five - it quadruples the amount.
NEWEST EDIT: So as it turns out, it was the for loop that I was using to try and increment the sequence. I got rid of the loop and hardcoded the sequence to 1. That fixed it.
To apply multiple templates to a single envelope you'll need to use the compositeTemplates structure.
compositeTemplates can get complex very quickly but they do allow for great flexibility and functionality for your envelopes. The API documentation is the best place to read about compositeTemplates but as previously mentioned the April 2012 Templates Webinar is also a good resource. The third example provides a basic use of compositeTemplates in that it shows you how to combine two server templates into one single envelope. You can use that as a base for your JSON.
To apply 2 server templates to a single envelope it uses the following JSON:
{
"emailSubject": "DocuSign Templates Webinar - Example 3",
"emailBlurb": "Example #3 - Composite Templates",
"status": "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence": "1",
"templateId": "55A80182-2E9F-435D-9B16-FD1E1C0F9D74"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "firstrecipient#gmail.com",
"name": "John Doe",
"recipientId": "1",
"roleName": "RoleOne"
}
]
}
}
]
},
{
"serverTemplates": [
{
"sequence": "2",
"templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA"
}
],
"inlineTemplates": [
{
"sequence": "2",
"recipients": {
"signers": [
{
"email": "secondrecipient#gmail.com",
"name": "Jane Doe",
"recipientId": "1",
"roleName": "RoleOne"
}
]
}
}
]
}
]
}
Note that the sequence value for each template determines the order of template application to the envelope. So in other words, the sequence value determines the document order, but since the templates might have matching/conflicting info (in terms of template roles for instance) the sequence value might also affect the end result of the envelope.
I use this method to generate a pass: public function setJSON($JSON) {
if(json_decode($JSON) !== false) {
$this->JSON = $JSON;
return true;
}
$this->sError = 'This is not a JSON string.';
return false;
}
I call this method to generate pass by: $pass->setJSON('{
"passTypeIdentifier": "'.$passTypeID.'",
"formatVersion": 1,
..............
"barcode": {
"altText" : "'.$alt.'",
"format" : "PKBarcodeFormatPDF417",
"message": "Member-Card",
"messageEncoding": "iso-8859-1",
"changeMessage" : "This pass now has altText %# !"
},
"locations" : [
{
"longitude" : 104.89529371261597,
"latitude" : 11.576150037278605,
"relevantText": "CamMob (dis. 1%)"
},
.....................
]
}');
But now I don't write those locations statically and I get those data from database by : $query5 = mysql_query("select * from company");
while ($row5 = mysql_fetch_array($query5)){
$companyName = $row5['relevantTextName'];
$discount = $row5['relevantTextDiscount'];
$long = $row5['longitute'];
$lat = $row5['latitute'];
$link = $row5['link'];
$location['locations'][] = array("longitute" => $long, "latitute" => $lat, "relevantText" => $companyName." (" . $discount. "%)" );
}
$jsonString = json_encode($location) ;
error_log("Locations: ".$jsonString,0);
$pass->setJSON($jsonString);
$pass->setJSON('{
"passTypeIdentifier": "'.$passTypeID.'",
"barcode": {
"altText" : "'.$alt.'",
"format" : "PKBarcodeFormatPDF417",
"message": "Member-Card",
"messageEncoding": "iso-8859-1",
"changeMessage" : "This pass now has altText %# !"
}
}');</pre>
There is no error when I test for updating pass, but I cannot see the pass on lock screen like before. Thus it means that I not yet include those locations to the pass. What should I change ? Is it the problem of method setJSON ? If I do like this, how can I combine these 2 jsons to become together ?
Rather than constructing the JSON directly, construct an array first, then transform it into JSON.
$pass_data = array("passTypeIdentifier" => $passTypeID,
"formatVersion" => 1,
"barcode" => array (
"altText" => $alt,
"format" => "PKBarcodeFormatPDF417",
"message" => "Member-Card",
"messageEncoding" => "utf-8", // use UTF8 in case you want to encode Khmer or other non ASCII
"changeMessage" => "This pass now has altText %# !"
),
"locations" => $locationsArray,
"organizationName" => "Digi club card",
"description" => "Membership card",
"logoText" => "Digiclub",
"foregroundColor" => "rgb(0,0,0)",
"backgroundColor" => "rgb(211,211,211)",
"generic" => array (
"headerFields" => array(
array ( "key" => "Status",
"label" => " ",
"value" => "Membership card"
),
),
"primaryFields" => array(
array ( "key" => "Name",
"value" => $memberName,
),
),
"secondaryFields" => array(
// Secondary Field data
),
"auxiliaryFields" => array(
// Auxiliary Field data
),
"backFields" => array(
// Backfiels Field data
),
)
);
Then transform the array into JSON:
$pass->setJSON(json_encode($pass_data));