Razor pay route payments using php - javascript

ive been using razor pays normal checkout feature
<script type="text/javascript">
var options = {
"key": "rzp_****_*********",
"amount": 10000,
"currency": "INR",
"name": "XYZ",
"description": "Payment For Appointment at XYZ Limited",
"image": "https://XYZ.in/public/theme/images/re-logo.png",
"handler": function (response) {
var payid = response.razorpay_payment_id;
$('#transaction_id').val(payid);
$('#paymentform').submit();
},
"prefill": {
"name": "Name",
"email": "Email"
},
"notes": {
"address": "note value"
},
"theme": {
"color": "#F37254"
}
};
var rzp1 = new Razorpay(options);
document.getElementById('payonlinebutton').onclick = function (e) {
rzp1.open();
e.preventDefault();
}
</script>
But i want to use route payments now, and on razorpay's document they have only sample code for curl
Can anyone help me with php solution if there is any.
i got his document but the concept is not that clear
https://razorpay.com/docs/server-integration/php/usage/#route

Install PHP SDK https://razorpay.com/docs/server-integration/php/ and call the function as per need

Related

How do I update the shipping options at checkout in BigCommerce

I've written a custom app which uses a PHP server for the back end and the bigcommerce checkout/cart sdk with JS for the front end.
Basically this is what I want to do:
Retrieve Rates using my php app and a 3rd party api (This works)
Display said rates as selectable options (This works)
Update the checkout and consignment (This works but not 100%)
Update the cart shipping method and total (This is where I am stuck)
After I get the rates from the PHP server, I dynamically build the list's HTML.
I randomly assign shipping method id's (As I have no idea how this gets generated but it appears to be fairly random)
When I click on a shipping option this code runs (Please note that 'option' is a variable within a foreach loop
console.dir(checkoutObj);
if(checkoutObj.consignments.length < 1){
console.log('no consign');
} else {
var selectedShipping = checkoutObj.consignments[0].selectedShippingOption;
selectedShipping.cost = parseFloat(option['grandtotmrkup']);
selectedShipping.description = option['CarrierName'] + '-' + option['CarrierService'];
selectedShipping.id = this.value;
selectedShipping.type = 'weight_based_shipping';
checkoutObj.consignments[0].shippingCost = parseFloat(option['grandtotmrkup']);
checkoutObj.shippingCostBeforeDiscount = parseFloat(option['grandtotmrkup']);
checkoutObj.shippingCostTotal = parseFloat(option['grandtotmrkup']);
console.log('updated checkout obj');
console.dir(checkoutObj);
var updated = service.updateCheckout(checkoutObj);
console.log('updated');
console.dir(state.data.getCheckout());
console.log('updating consignment');
console.dir(
service.updateConsignment({'id':consignID,'shippingOptionId':shippingMethodId})
);
console.dir(state.data.getConsignments());
When it runs service.updateConsignment I get the following response for the consignments section of the object:
"consignments": [
{
"id": "5f732875d039f",
"shippingCost": 0,
"handlingCost": 0,
"couponDiscounts": [],
"discounts": [],
"lineItemIds": [
"4f557702-4f9d-45ec-943a-c72ea963ccc7"
],
"selectedShippingOption": {
"id": "4dcbf24f457dd67d5f89bcf374e0bc9b",
"type": "freeshipping",
"description": "Free Shipping",
"imageUrl": "",
"cost": 0,
"transitTime": "",
"additionalDescription": ""
},
"shippingAddress": {
"firstName": "1",
"lastName": "1",
"email": "",
"company": "",
"address1": "1 street",
"address2": "",
"city": "MITCHAM",
"stateOrProvince": "Victoria",
"stateOrProvinceCode": "VIC",
"country": "Australia",
"countryCode": "AU",
"postalCode": "3132",
"phone": "",
"customFields": [],
"shouldSaveAddress": true
},
"availableShippingOptions": [
{
"id": "9ba45e71fe66e1cd757f022dcae331b0",
"type": "shipping_pickupinstore",
"description": "Pickup In Store",
"imageUrl": "",
"cost": 0,
"transitTime": "",
"isRecommended": false,
"additionalDescription": ""
},
{
"id": "4dcbf24f457dd67d5f89bcf374e0bc9b",
"type": "freeshipping",
"description": "Free Shipping",
"imageUrl": "",
"cost": 0,
"transitTime": "",
"isRecommended": true,
"additionalDescription": ""
}
]
}
],
I'm not sure if it's because my shipping options aren't in the Available Shipping Options Section of the object?
Does anyone know how I can get my shipping methods in there? Or is this being caused because I append the methods dyanmically via HTML?
I'm new to BC so please excuse any ignorance.
I don't think you're going to be able to inject a shipping option into the checkout this way, I think you'd need to look at using the Shipping Methods API in your PHP app and then the options should be available as per usual.

After ajax google analytics tag not working

I am using google analytics to measure every event on my web page. When gtag scripts embed directly html working well (i always confirm event google anlytics ) but after ajax codes not working and no action in google analytics center. What does that i miss?
Here is my ajax codes for add to cart event
function addtocart(){
$.post(url,{}, function (response) {
$("#shopping-cart").html(response.Render);
$(".sepette_modal").css("display", "flex");
setTimeout(() => {
$(".sepette_modal").css("display", "none");
$('#' + Urun_kodu).html(`
<i class="icon_cart_alt"></i>Add to cart
`);
}, 1500);
//below gtag() function not working
gtag('event', 'add_to_cart', {
"transaction_id": response.Urun_kodu,
"affiliation": "Marketcimrisi",
"value":response.Fiyat,
"currency": "TRY",
"tax": 0,
"shipping": 0,
"items": [
{
"id": response.Urun_kodu,
"name": response.Urun_adi,
"list_name": response.Detaykategori,
"brand": response.Marka,
"category": response.Detaykategori,
"variant": "",
"list_position": 1,
"quantity": 1,
"price": response.Fiyat
},
]
},'json');
});
You shouldn't send transaction information with add to cart event. To measure the addition of a product to a shopping cart, send an add_to_cart event with the product information:
gtag('event', 'add_to_cart', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
]
});
https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_additions_to_and_removals_from_shopping_carts
Finally i have found the solution after an ajax request must recall google analytics tags
$.getScript("https://www.googletagmanager.com/gtag/js?id=UA-171652858-1",function(){});
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('event', 'purchase', {
"transaction_id": response.SiparisNumarasi,
"affiliation": "Marketcimrisi",
"value":response.OdenenTutar,
"currency": "TRY",
"tax": 0,
"shipping": 0,
"items": JSON.stringify(response.Urunler)
});

Razorpay standard checkout razorpay_order_id missing in response (only razorpay_payment_id found)

I am trying to integrate the Razorpay payment gateway.
The payment process was a success but I don't get razorpay_order_id in response
This is my code
Pay
<script>
var options = {
"key": "YOUR_KEY_ID", // Your Key
"amount": "50000", // Amount is in currency subunits, in Paise
"currency": "INR",
"name": "Acme Corp",
"description": "Test Transaction",
"image": "https://example.com/your_logo",
"razorpay_order_id": "order_9A33XWu170gUtm", //This is a sample Order ID. Pass the `id` obtained in the response of Step 1
"handler": function (response){
alert(response.razorpay_payment_id);
alert(response.razorpay_order_id);
},
"prefill": {
"name": "Gaurav Kumar",
"email": "gaurav.kumar#example.com",
"contact": "9999999999"
},
"notes": {
"address": "Razorpay Corporate Office"
},
"theme": {
"color": "#F37254"
}
};
var rzp1 = new Razorpay(options);
document.getElementById('rzp-button1').onclick = function(e){
rzp1.open();
e.preventDefault();
}
1: Say, user selected a product and order is placed in cart with order_id="user_order_id".
2: Before making payment, first create "razor_order_id" in your database table corresponds to your product order_id=user_order_id.
3: $a = new Api(env('RAZOR_KEY'), env('RAZOR_SECRET'));
$order = $a->order->create(['receipt' => user_order_id,
'amount'=> $cart['total_amount']*100, 'currency'=> 'INR']);
$razor_order_id = $order->id;
$razor_order_status = $order->status;
DB::table('orders')->where('order_id',$user_order_id)->update(['razor_order_id' => $razor_order_id,'razor_order_status'=>$razor_order_status]);
Session::put('razor_order_id',$razor_order_id);
4: now pass your session variable '$razor_order_id'as values to your key "razorpay_order_id" in $options.
5: now run your above script and you will receive 'razorpay_order_id' in response.

unable to integrate razorpay in angular 4

I am trying to integrate the razorPay payment gateway.
payNow( ) {
var options = {
"key": "rzp_test_dveDexCQKoGszl",
"amount":((this.buyNow==1)?this.shared.totalAmountWithDisocuntBuyNow:this.shared.totalAmountWithDisocunt)*100, // 2000 paise = INR 20
"name": " MARKET",
"description": "Order #",
"handler": function (response){
console.log(response);
alert(response.razorpay_payment_id);
this.paid();
this.shared.addOrder(this.buyNow,response.razorpay_payment_id);
},
"prefill": {
"name": this.shared.orderDetails.billing_firstname + " " + this.shared.orderDetails.billing_lastname,
"email": this.shared.customerData.customers_email_address,
"contact": this.shared.customerData.customers_telephone,
},
"notes": {
"address": this.shared.orderDetails.billing_street_address+', '+this.shared.orderDetails.billing_city+', '+this.shared.orderDetails.billing_state+' '+this.shared.orderDetails.billing_postcode+', '+this.shared.orderDetails.billing_country
},
"theme": {
"color": "blue"
}
};
var rzp1 = new Razorpay(options);
rzp1.open();
// body...
}
paid()
{alert();}
I have defined in handler the callback function. But issue is it successfully logs the response and alerts it too but it does not calls
this.paid()
or
this.shared.addOrder(this.buyNow,response.razorpay_payment_id);
There are no console errors nothing. It just does not calls any of above methioned functions.
Call the handler function by binding it to function using following syntax
"handler":this.shared.addOrder.bind(this,this.buyNow) ,
This worked.

Issue On Accessing to In Script JSON object in jQuery Ajax

Can you please take a look at This Demo and let me know how to access to JSON object like credit which is declared inside the same requester script as:
var credit = [{
"name": "John Johnson",
"street": "Oslo West 16",
"phone": "222 7894562"
}, {
"name": "Davie Amber",
"street": "Alberta 52",
"phone": "555 1234567"
}, {
"name": "Marck William",
"street": "Delestre 125",
"phone": "666 7254599"
}];
$("button").click(function () {
$.ajax({
url: "credit",
success: function (result) {
$("#div1").html(result);
}
});
});
I know in real world, there is no need to do this since is doable in simple JavaScript but for doing a specific test I need to provide the test environment like this which is running by $.ajax() method.
Thanks
mockjax might be what you looking for.
Here is your example with some tweaks to get it to output to the div (doesn't work in chrome for me because of the mockjax script mime type)
Html
<div id="div1"></div>
<button>Get Data</button>
Javascript
$(document).ready(function () {
$.mockjax({
url: '/someurl',
responseText: [{
"name": "John Johnson",
"street": "Oslo West 16",
"phone": "222 7894562"
},
{
"name": "Davie Amber",
"street": "Alberta 52",
"phone": "555 1234567"
},
{
"name": "Marck William",
"street": "Delestre 125",
"phone": "666 7254599"
}]
});
$("button").click(function () {
$.ajax({
url: "/someurl",
success: function (result) {
console.log(result);
$("#div1").html(JSON.stringify(result));
}
});
});
});

Categories