├── README.md ├── database └── transaction.sql ├── index.php ├── instamojo ├── Instamojo.php └── cacert.pem ├── pay.php └── thankyou.php /README.md: -------------------------------------------------------------------------------- 1 | # Payment-Gateway-Using-PHP 2 | Instamozo -PaymentGateway-PHP (PHP , Bootstrap 4+ , Css , HTML-5 , Jquery) 3 | 4 | >First you create an account on Instamojo https://test.instamojo.com/ 5 | 6 | 7 | >All Details for Testing Purpose Only ! 8 | >Select -> Card Payment type 9 | 10 | ``` text 11 | Debit = 4242 4242 4242 4242 12 | Expiry =1221 13 | cvv = 111 14 | security pin = 1221 15 | ``` 16 | 17 | Assists you to programmatically create, edit and delete Links on Instamojo in PHP 18 | ![home](https://user-images.githubusercontent.com/45098599/79463263-3b416a00-8016-11ea-89eb-a05cc308f9a9.png) 19 | ![fill](https://user-images.githubusercontent.com/45098599/79463273-3ed4f100-8016-11ea-8770-0baf02b7534e.png) 20 | ![fill-card-details](https://user-images.githubusercontent.com/45098599/79463331-5613de80-8016-11ea-8efa-036630acdc25.png) 21 | ![instamozo](https://user-images.githubusercontent.com/45098599/79463348-5b712900-8016-11ea-95ca-6c0b38377089.png) 22 | ![enter security-pin](https://user-images.githubusercontent.com/45098599/79463372-6330cd80-8016-11ea-8c39-5049637e5dd9.png) 23 | ![thank-you-page](https://user-images.githubusercontent.com/45098599/79463383-67f58180-8016-11ea-8de0-2cfb0c7f4136.png) 24 | 25 | ![Payment Gateway GIF-downsized](https://user-images.githubusercontent.com/45098599/79464303-8a3bcf00-8017-11ea-916a-49905128caaa.gif) 26 | 27 | 28 | . 29 | 30 | Note: If you're using this wrapper with our sandbox environment https://test.instamojo.com/ then you should pass 'https://test.instamojo.com/api/1.1/' as third argument to the Instamojo class while initializing it. API key and Auth token for the same can be obtained from https://test.instamojo.com/developers/ (Details: Test Or Sandbox Account). 31 | 32 | >$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN, 'https://test.instamojo.com/api/1.1/'); 33 | 34 | 35 | Installing via Composer 36 | $ php composer.phar require instamojo/instamojo-php 37 | Note: If you're not using Composer then directly include the contents of src directory in your project. 38 | 39 | >Usage 40 | ```php 41 | $api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN); 42 | Create a new Payment Request 43 | try { 44 | $response = $api->paymentRequestCreate(array( 45 | "purpose" => "FIFA 16", 46 | "amount" => "3499", 47 | "send_email" => true, 48 | "email" => "foo@example.com", 49 | "redirect_url" => "http://www.example.com/handle_redirect.php" 50 | )); 51 | print_r($response); 52 | } 53 | catch (Exception $e) { 54 | print('Error: ' . $e->getMessage()); 55 | } 56 | ``` 57 | This will give you JSON object containing details of the Payment Request that was just created. 58 | 59 | Get the status or details of a Payment Request 60 | ```php 61 | try { 62 | $response = $api->paymentRequestStatus(['PAYMENT REQUEST ID']); 63 | print_r($response); 64 | } 65 | catch (Exception $e) { 66 | print('Error: ' . $e->getMessage()); 67 | } 68 | ``` 69 | This will give you JSON object containing details of the Payment Request and the payments related to it. Key for payments is 'payments'. 70 | 71 | Here ['PAYMENT REQUEST ID'] is the value of 'id' key returned by the paymentRequestCreate() query. 72 | 73 | >Get the status of a Payment related to a Payment Request 74 | ```php 75 | try { 76 | $response = $api->paymentRequestPaymentStatus(['PAYMENT REQUEST ID'], ['PAYMENT ID']); 77 | print_r($response['purpose']); // print purpose of payment request 78 | print_r($response['payment']['status']); // print status of payment 79 | } 80 | catch (Exception $e) { 81 | print('Error: ' . $e->getMessage()); 82 | } 83 | ``` 84 | 85 | This will give you JSON object containing details of the Payment Request and the payments related to it. Key for payments is 'payments'. 86 | 87 | Here ['PAYMENT REQUEST ID'] is the value of 'id' key returned by the paymentRequestCreate() query and ['PAYMENT ID'] is the Payment ID received with redirection URL or webhook. 88 | 89 | >Get a list of Payment Requests 90 | ```php 91 | try { 92 | $response = $api->paymentRequestsList(); 93 | print_r($response); 94 | } 95 | catch (Exception $e) { 96 | print('Error: ' . $e->getMessage()); 97 | } 98 | ``` 99 | 100 | This will give you an array containing Payment Requests created so far. Note that the payments related to individual Payment Request are not returned with this query. 101 | 102 | paymentRequestsList() also accepts optional parameters for pagination as well as filtering based on created_at and updated_at fields. 103 | 104 | paymentRequestsList($limit=null, $page=null, $max_created_at=null, $min_created_at=null, $max_modified_at=null, $min_modified_at=null) 105 | For example: 106 | 107 | $response = $api->paymentRequestsList(50, 1, "2015-11-19T10:12:19Z", "2015-10-29T12:51:36Z"); 108 | For details related to supported datetime format check the documentation: https://www.instamojo.com/developers/request-a-payment-api/#toc-filtering-payment-requests 109 | 110 | >Available Request a Payment Functions 111 | >You have these functions to interact with the Request a Payment API: 112 | 113 | paymentRequestCreate(array $payment_request) Create a new Payment Request. 114 | paymentRequestStatus($id) Get details of Payment Request specified by its unique id. 115 | paymentRequestsList(array $datetime_limits) Get a list of all Payment Requests. The $datetime_limits argument is optional an can be used to filter Payment Requests by their creation and modification date. 116 | Payment Request Creation Parameters 117 | Required 118 | purpose: Purpose of the payment request. (max-characters: 30) 119 | amount: Amount requested (min-value: 9 ; max-value: 200000) 120 | Optional 121 | buyer_name: Name of the payer. (max-characters: 100) 122 | email: Email of the payer. (max-characters: 75) 123 | phone: Phone number of the payer. 124 | send_email: Set this to true if you want to send email to the payer if email is specified. If email is not specified then an error is raised. (default value: false) 125 | send_sms: Set this to true if you want to send SMS to the payer if phone is specified. If phone is not specified then an error is raised. (default value: false) 126 | redirect_url: set this to a thank-you page on your site. Buyers will be redirected here after successful payment. 127 | webhook: set this to a URL that can accept POST requests made by Instamojo server after successful payment. 128 | allow_repeated_payments: To disallow multiple successful payments on a Payment Request pass false for this field. If this is set to false then the link is not accessible publicly after first successful payment, though you can still access it using API(default value: true). 129 | 130 | >Further documentation is available at https://docs.instamojo.com/v1.1/docs 131 | -------------------------------------------------------------------------------- /database/transaction.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.8.5 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: Apr 15, 2020 at 07:43 PM 7 | -- Server version: 10.1.38-MariaDB 8 | -- PHP Version: 7.3.3 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET AUTOCOMMIT = 0; 12 | START TRANSACTION; 13 | SET time_zone = "+00:00"; 14 | 15 | 16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 19 | /*!40101 SET NAMES utf8mb4 */; 20 | 21 | -- 22 | -- Database: `payment` 23 | -- 24 | 25 | -- -------------------------------------------------------- 26 | 27 | -- 28 | -- Table structure for table `transaction` 29 | -- 30 | 31 | CREATE TABLE `transaction` ( 32 | `id` int(11) NOT NULL, 33 | `name` varchar(255) NOT NULL, 34 | `email` varchar(255) NOT NULL, 35 | `phone` varchar(10) NOT NULL, 36 | `amount` int(255) DEFAULT NULL, 37 | `pay_to` varchar(255) NOT NULL, 38 | `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 39 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 40 | 41 | -- 42 | -- Dumping data for table `transaction` 43 | -- 44 | 45 | INSERT INTO `transaction` (`id`, `name`, `email`, `phone`, `amount`, `pay_to`, `created_at`) VALUES 46 | (1, 'SHUBHAM SINGH', 'priyadrashansingh@gmail.com', '8400840468', 100, 'Modi Care Releaf fund.', '2020-04-15 06:42:12'), 47 | (2, 'KISHAN MAURYA', 'fullstack49kishan@gmail.com', '9598608579', 100, 'Modi Care Releaf fund.', '2020-04-15 06:42:16'), 48 | (3, 'KISHAN MAURYA', 'fullstack49kishan@gmail.com', '9598608579', 100, 'Modi Care Releaf fund.', '2020-04-15 06:45:00'), 49 | (4, 'Prateek Pandey', 'prateekpandey736@gmail.com', '8687767493', 101, 'Modi Care Releaf fund.', '2020-04-15 07:42:15'), 50 | (5, 'Manpreet Singh', 'manpreetsinghmakhija@gmail.com', '7014913728', 500, 'Modi Care Releaf fund.', '2020-04-15 07:44:55'), 51 | (6, 'KISHAN MAURYA', 'fullstack49kishan@gmail.com', '9598608579', 990, 'Modi Care Releaf fund.', '2020-04-15 14:05:48'), 52 | (7, 'KISHAN MAURYA', 'fullstack49kishan@gmail.com', '9598608579', 4950, 'Modi Care Releaf fund.', '2020-04-15 14:08:47'), 53 | (8, 'KISHAN MAURYA', 'fullstack49kishan@gmail.com', '9598608579', 9900, 'Modi Care Releaf fund.', '2020-04-15 14:18:52'), 54 | (9, 'KISHAN MAURYA', 'fullstack49kishan@gmail.com', '9598608579', 1485, 'Modi Care Releaf fund.', '2020-04-15 14:22:03'), 55 | (10, 'Devesh Pandey', 'deveshpandeyy007@gmail.com', '7398683627', 990, 'Modi Care Releaf fund.', '2020-04-15 14:33:46'); 56 | 57 | -- 58 | -- Indexes for dumped tables 59 | -- 60 | 61 | -- 62 | -- Indexes for table `transaction` 63 | -- 64 | ALTER TABLE `transaction` 65 | ADD PRIMARY KEY (`id`); 66 | 67 | -- 68 | -- AUTO_INCREMENT for dumped tables 69 | -- 70 | 71 | -- 72 | -- AUTO_INCREMENT for table `transaction` 73 | -- 74 | ALTER TABLE `transaction` 75 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11; 76 | COMMIT; 77 | 78 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 79 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 80 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 81 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Payment 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 |
18 |
19 |
20 |

Payment Gateway Using PHP

21 |
22 |
23 |
24 |
25 |
26 |
27 |

28 | Payment Checkout 29 |

30 |
31 |
32 |
33 | 34 |
35 | 36 |
37 | 38 |
39 | 40 |
41 | 42 |
43 | 44 |
45 | 46 |
47 | 48 |
49 |
50 | 51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /instamojo/Instamojo.php: -------------------------------------------------------------------------------- 1 | api_key = (string) $api_key; 22 | $this->auth_token = (string) $auth_token; 23 | if(!is_null($endpoint)){ 24 | $this->endpoint = (string) $endpoint; 25 | } 26 | } 27 | 28 | public function __destruct() 29 | { 30 | if(!is_null($this->curl)) { 31 | curl_close($this->curl); 32 | } 33 | } 34 | 35 | /** 36 | * @return array headers with Authentication tokens added 37 | */ 38 | private function build_curl_headers() 39 | { 40 | $headers = array("X-Api-key: $this->api_key"); 41 | if($this->auth_token) { 42 | $headers[] = "X-Auth-Token: $this->auth_token"; 43 | } 44 | return $headers; 45 | } 46 | 47 | /** 48 | * @param string $path 49 | * @return string adds the path to endpoint with. 50 | */ 51 | private function build_api_call_url($path) 52 | { 53 | if (strpos($path, '/?') === false and strpos($path, '?') === false) { 54 | return $this->endpoint . $path . '/'; 55 | } 56 | return $this->endpoint . $path; 57 | 58 | } 59 | 60 | private function getParamsArray( $limit , $page ) 61 | { 62 | $params = array(); 63 | if (!is_null($limit)) { 64 | $params['limit'] = $limit; 65 | } 66 | 67 | if (!is_null($page)) { 68 | $params['page'] = $page; 69 | } 70 | 71 | return $params; 72 | } 73 | 74 | /** 75 | * @param string $method ('GET', 'POST', 'DELETE', 'PATCH') 76 | * @param string $path whichever API path you want to target. 77 | * @param array $data contains the POST data to be sent to the API. 78 | * @return array decoded json returned by API. 79 | */ 80 | private function api_call($method, $path, array $data=null) 81 | { 82 | $path = (string) $path; 83 | $method = (string) $method; 84 | $data = (array) $data; 85 | $headers = $this->build_curl_headers(); 86 | $request_url = $this-> build_api_call_url($path); 87 | 88 | $options = array(); 89 | $options[CURLOPT_HTTPHEADER] = $headers; 90 | $options[CURLOPT_RETURNTRANSFER] = true; 91 | 92 | if($method == 'POST') { 93 | $options[CURLOPT_POST] = 1; 94 | $options[CURLOPT_POSTFIELDS] = http_build_query($data); 95 | } else if($method == 'DELETE') { 96 | $options[CURLOPT_CUSTOMREQUEST] = 'DELETE'; 97 | } else if($method == 'PATCH') { 98 | $options[CURLOPT_POST] = 1; 99 | $options[CURLOPT_POSTFIELDS] = http_build_query($data); 100 | $options[CURLOPT_CUSTOMREQUEST] = 'PATCH'; 101 | } else if ($method == 'GET' or $method == 'HEAD') { 102 | if (!empty($data)) { 103 | /* Update URL to container Query String of Paramaters */ 104 | $request_url .= '?' . http_build_query($data); 105 | } 106 | } 107 | // $options[CURLOPT_VERBOSE] = true; 108 | $options[CURLOPT_URL] = $request_url; 109 | $options[CURLOPT_SSL_VERIFYPEER] = true; 110 | $options[CURLOPT_CAINFO] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacert.pem'; 111 | 112 | $this->curl = curl_init(); 113 | $setopt = curl_setopt_array($this->curl, $options); 114 | $response = curl_exec($this->curl); 115 | $headers = curl_getinfo($this->curl); 116 | 117 | $error_number = curl_errno($this->curl); 118 | $error_message = curl_error($this->curl); 119 | $response_obj = json_decode($response, true); 120 | 121 | if($error_number != 0){ 122 | if($error_number == 60){ 123 | throw new \Exception("Something went wrong. cURL raised an error with number: $error_number and message: $error_message. " . 124 | "Please check http://stackoverflow.com/a/21114601/846892 for a fix." . PHP_EOL); 125 | } 126 | else{ 127 | throw new \Exception("Something went wrong. cURL raised an error with number: $error_number and message: $error_message." . PHP_EOL); 128 | } 129 | } 130 | 131 | if($response_obj['success'] == false) { 132 | $message = json_encode($response_obj['message']); 133 | throw new \Exception($message . PHP_EOL); 134 | } 135 | return $response_obj; 136 | } 137 | 138 | /** 139 | * @return string URL to upload file or cover image asynchronously 140 | */ 141 | public function getUploadUrl() 142 | { 143 | $result = $this->api_call('GET', 'links/get_file_upload_url', array()); 144 | return $result['upload_url']; 145 | } 146 | 147 | /** 148 | * @param string $file_path 149 | * @return string JSON returned when the file upload is complete. 150 | */ 151 | public function uploadFile($file_path) 152 | { 153 | $upload_url = $this->getUploadUrl(); 154 | $file_path = realpath($file_path); 155 | $file_name = basename($file_path); 156 | $ch = curl_init(); 157 | $data = array('fileUpload' => $this->getCurlValue($file_path, $file_name)); 158 | curl_setopt($ch, CURLOPT_URL, $upload_url); 159 | curl_setopt($ch, CURLOPT_POST, 1); 160 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 161 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 162 | return curl_exec($ch); 163 | } 164 | 165 | public function getCurlValue($file_path, $file_name, $content_type='') 166 | { 167 | // http://stackoverflow.com/a/21048702/846892 168 | // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax 169 | // See: https://wiki.php.net/rfc/curl-file-upload 170 | if (function_exists('curl_file_create')) { 171 | return curl_file_create($file_path, $content_type, $file_name); 172 | } 173 | 174 | // Use the old style if using an older version of PHP 175 | $value = "@{$file_path};filename=$file_name"; 176 | if ($content_type) { 177 | $value .= ';type=' . $content_type; 178 | } 179 | 180 | return $value; 181 | } 182 | 183 | /** 184 | * Uploads any file or cover image mentioned in $link and 185 | * updates it with the json required by the API. 186 | * @param array $link 187 | * @return array $link updated with uploaded file information if applicable. 188 | */ 189 | public function uploadMagic(array $link) 190 | { 191 | if(!empty($link['file_upload'])) { 192 | $file_upload_json = $this->uploadFile($link['file_upload']); 193 | $link['file_upload_json'] = $file_upload_json; 194 | unset($link['file_upload']); 195 | } 196 | if(!empty($link['cover_image'])) { 197 | $cover_image_json = $this->uploadFile($link['cover_image']); 198 | $link['cover_image_json'] = $cover_image_json; 199 | unset($link['cover_image']); 200 | } 201 | return $link; 202 | } 203 | 204 | /** 205 | * Authenticate using username and password of a user. 206 | * Automatically updates the auth_token value. 207 | * @param array $args contains username=>USERNAME and password=PASSWORD 208 | * @return array AuthToken object. 209 | */ 210 | public function auth(array $args) 211 | { 212 | $response = $this->api_call('POST', 'auth', $args); 213 | $this->auth_token = $response['auth_token']['auth_token']; 214 | return $this->auth_token; 215 | } 216 | 217 | /** 218 | * @return array list of Link objects. 219 | */ 220 | public function linksList($limit, $path) 221 | { 222 | $response = $this->api_call('GET', 'links', $this->getParamsArray($limit , $path) ); 223 | return $response['links']; 224 | } 225 | 226 | /** 227 | * @return array single Link object. 228 | */ 229 | public function linkDetail($slug) 230 | { 231 | $response = $this->api_call('GET', 'links/' . $slug, array()); 232 | return $response['link']; 233 | } 234 | 235 | /** 236 | * @return array single Link object. 237 | */ 238 | public function linkCreate(array $link) 239 | { 240 | if(empty($link['currency'])){ 241 | $link['currency'] = 'INR'; 242 | } 243 | $link = $this->uploadMagic($link); 244 | $response = $this->api_call('POST', 'links', $link); 245 | return $response['link']; 246 | } 247 | 248 | /** 249 | * @return array single Link object. 250 | */ 251 | public function linkEdit($slug, array $link) 252 | { 253 | $link = $this->uploadMagic($link); 254 | $response = $this->api_call('PATCH', 'links/' . $slug, $link); 255 | return $response['link']; 256 | } 257 | 258 | /** 259 | * @return array single Link object. 260 | */ 261 | public function linkDelete($slug) 262 | { 263 | $response = $this->api_call('DELETE', 'links/' . $slug, array()); 264 | return $response; 265 | } 266 | 267 | /** 268 | * @return array list of Payment objects. 269 | */ 270 | public function paymentsList($limit = null, $page = null) 271 | { 272 | $response = $this->api_call('GET', 'payments', $this->getParamsArray($limit , $page)); 273 | return $response['payments']; 274 | } 275 | 276 | /** 277 | * @param string payment_id as provided by paymentsList() or Instamojo's webhook or redirect functions. 278 | * @return array single Payment object. 279 | */ 280 | public function paymentDetail($payment_id) 281 | { 282 | $response = $this->api_call('GET', 'payments/' . $payment_id, array()); 283 | return $response['payment']; 284 | } 285 | 286 | 287 | ///// Request a Payment ///// 288 | 289 | /** 290 | * @param array single PaymentRequest object. 291 | * @return array single PaymentRequest object. 292 | */ 293 | public function paymentRequestCreate(array $payment_request) 294 | { 295 | $response = $this->api_call('POST', 'payment-requests', $payment_request); 296 | return $response['payment_request']; 297 | } 298 | 299 | /** 300 | * @param string id as provided by paymentRequestCreate, paymentRequestsList, webhook or redirect. 301 | * @return array single PaymentRequest object. 302 | */ 303 | public function paymentRequestStatus($id) 304 | { 305 | $response = $this->api_call('GET', 'payment-requests/' . $id, array()); 306 | return $response['payment_request']; 307 | } 308 | 309 | /** 310 | * @param string id as provided by paymentRequestCreate, paymentRequestsList, webhook or redirect. 311 | * @param string payment_id as received with the redirection URL or webhook. 312 | * @return array single PaymentRequest object. 313 | */ 314 | public function paymentRequestPaymentStatus($id, $payment_id) 315 | { 316 | $response = $this->api_call('GET', 'payment-requests/' . $id . '/' . $payment_id, array()); 317 | return $response['payment_request']; 318 | } 319 | 320 | 321 | /** 322 | * @param array datetime_limits containing datetime data with keys 'max_created_at', 'min_created_at', 323 | * 'min_modified_at' and 'max_modified_at' in ISO 8601 format(optional). 324 | * @return array containing list of PaymentRequest objects. 325 | * For more information on the allowed date formats check the 326 | * docs: https://www.instamojo.com/developers/request-a-payment-api/#toc-filtering-payment-requests 327 | */ 328 | public function paymentRequestsList( $limit = null , $page = null , $max_created_at = null , $min_created_at = null , $max_modified_at = null , $min_modified_at = null ) 329 | { 330 | $endpoint = 'payment-requests'; 331 | 332 | $params = array(); 333 | if (!is_null($max_created_at)) { 334 | $params['max_created_at'] = $max_created_at; 335 | } 336 | 337 | if (!is_null($min_created_at)) { 338 | $params['min_created_at'] = $min_created_at; 339 | } 340 | 341 | if (!is_null($min_modified_at)) { 342 | $params['min_modified_at'] = $min_modified_at; 343 | } 344 | 345 | if (!is_null($$max_modified_at)) { 346 | $params['max_modified_at'] = $max_modified_at; 347 | } 348 | 349 | $response = $this->api_call('GET', 'payment-requests', array_merge($params , $this->getParamsArray($limit , $page))); 350 | return $response['payment_requests']; 351 | } 352 | 353 | 354 | ///// Refunds ///// 355 | 356 | /** 357 | * @param array single Refund object. 358 | * @return array single Refund object. 359 | */ 360 | public function refundCreate(array $refund) 361 | { 362 | $response = $this->api_call('POST', 'refunds', $refund); 363 | return $response['refund']; 364 | } 365 | 366 | /** 367 | * @param string id as provided by refundCreate or refundsList. 368 | * @return array single Refund object. 369 | */ 370 | public function refundDetail($id) 371 | { 372 | $response = $this->api_call('GET', 'refunds/' . $id, array()); 373 | return $response['refund']; 374 | } 375 | 376 | /** 377 | * @return array containing list of Refund objects. 378 | */ 379 | public function refundsList($limit, $path) 380 | { 381 | $response = $this->api_call('GET', 'refunds', $this->getParamsArray($limit, $path)); 382 | return $response['refunds']; 383 | } 384 | 385 | } 386 | ?> 387 | -------------------------------------------------------------------------------- /pay.php: -------------------------------------------------------------------------------- 1 | =99) { 4 | $name=$_POST['name']; 5 | $email=$_POST['email']; 6 | $phone=$_POST['phone']; 7 | $amount=$_POST['amt']; 8 | $pay_to='MCA Foundation (Save Tree , Save India)'; 9 | include 'instamojo\Instamojo.php'; 10 | $api = new Instamojo\Instamojo('test_3fca8eebb469e6292a0003326f6', 'test_69ae86fc88c4fccf0809d1641df', 'https://test.instamojo.com/api/1.1/'); 11 | try { 12 | $response = $api->paymentRequestCreate(array( 13 | "purpose" => $pay_to, 14 | "user_name" => $name, 15 | "email" => $email, 16 | "phone" => $phone, 17 | "amount" => $amount, 18 | "send_email" => true, 19 | "allow_repeated_payments" => false, 20 | "redirect_url" => "http://localhost/Payment/thankyou.php" 21 | )); 22 | // print_r($response); 23 | $url=$response['longurl']; 24 | header("location:$url"); 25 | } 26 | catch (Exception $e) { 27 | print('Error: ' . $e->getMessage()); 28 | } 29 | $query="INSERT INTO transaction (name,email,phone,amount,pay_to) VALUES ('$name','$email','$phone','$amount','$pay_to')"; 30 | $run=mysqli_query($con,$query); 31 | } 32 | ?> -------------------------------------------------------------------------------- /thankyou.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Thank You.! 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 24 | 25 | 26 | 27 | 28 | 29 | --------------------------------------------------------------------------------