Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout added #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ composer require razorpay/razorpay:2.*
# Usage

```php
require_once $_SERVER["DOCUMENT_ROOT"]."/vendor/autoload.php";
use Razorpay\Api\Api;

$api = new Api($api_key, $api_secret);
Expand All @@ -37,6 +38,9 @@ $order = $api->order->fetch($orderId);
$orders = $api->order->all($options); // Returns array of order objects
$payments = $api->order->fetch($orderId)->payments(); // Returns array of payment objects against an order

// Checkout
$api->checkout->init($orderId)

// Payments
$payments = $api->payment->all($options); // Returns array of payment objects
$payment = $api->payment->fetch($id); // Returns a particular payment
Expand Down
81 changes: 81 additions & 0 deletions src/Checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Razorpay\Api;

class Checkout
{
/**
* @param $id Order id description
*/
public function init($orderId)

{

$data = [
"order_id" => $orderId,
"name" => "DJ Tiesto",
"description" => "Tron Legacy",
"image" => "https://s29.postimg.org/r6dj1g85z/daft_punk.jpg",
"prefill" => [
"name" => "Daft Punk",
"email" => "[email protected]",
"contact" => "9999999999",
],
"notes" => [
"address" => "Hello World",
"merchant_order_id" => "12312321",
],
"theme" => ["color" => "#F37254"],
];

$json = json_encode($data);
$this->getCheckoutHtml($json);

}
private function getCheckoutHtml($json) {
$html = '
<button id="rzp-button1">Pay with Razorpay</button>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<form name="razorpayform" method="POST">
<input type="hidden" name="razorpay_payment_id" id="razorpay_payment_id">
<input type="hidden" name="razorpay_signature" id="razorpay_signature" >
</form>
<script>
// Checkout details as a json
var options = ' . $json . '

/**
* The entire list of Checkout fields is available at
* https://docs.razorpay.com/docs/checkout-form#checkout-fields
*/
options.handler = function (response){
alert("The payment was successful with " + response.razorpay_payment_id)
};

// Boolean whether to show image inside a white frame. (default: true)
options.theme.image_padding = false;

options.modal = {
ondismiss: function() {
console.log("This code runs when the popup is closed");
},
// Boolean indicating whether pressing escape key
// should close the checkout form. (default: true)
escape: true,
// Boolean indicating whether clicking translucent blank
// space outside checkout form should close the form. (default: false)
backdropclose: false
};

var rzp = new Razorpay(options);

document.getElementById("rzp-button1").onclick = function(e){
rzp.open();
e.preventDefault();
}
</script>';
echo $html;
}

}