Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
BIN
vendor/instamojo/instamojo-php/.DS_Store
vendored
Normal file
BIN
vendor/instamojo/instamojo-php/.DS_Store
vendored
Normal file
Binary file not shown.
3
vendor/instamojo/instamojo-php/.gitignore
vendored
Normal file
3
vendor/instamojo/instamojo-php/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea
|
||||
|
||||
/vendor/
|
||||
21
vendor/instamojo/instamojo-php/LICENSE
vendored
Normal file
21
vendor/instamojo/instamojo-php/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Instamojo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
148
vendor/instamojo/instamojo-php/OLD_API.md
vendored
Normal file
148
vendor/instamojo/instamojo-php/OLD_API.md
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
# Instamojo Old PHP API
|
||||
|
||||
**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](https://instamojo.zendesk.com/hc/en-us/articles/208485675-Test-or-Sandbox-Account)).
|
||||
|
||||
|
||||
```php
|
||||
$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN, 'https://test.instamojo.com/api/1.1/');
|
||||
```
|
||||
|
||||
|
||||
## Installing via [Composer](https://getcomposer.org/)
|
||||
```bash
|
||||
$ php composer.phar require instamojo/instamojo-php
|
||||
```
|
||||
|
||||
**Note**: If you're not using Composer then directly include the contents of `src` directory in your project.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN);
|
||||
```
|
||||
|
||||
### Create a product
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->linkCreate(array(
|
||||
'title'=>'Hello API',
|
||||
'description'=>'Create a new product easily',
|
||||
'base_price'=>100,
|
||||
'cover_image'=>'/path/to/photo.jpg'
|
||||
));
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you JSON object containing details of the product that was just created.
|
||||
|
||||
### Edit a product
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->linkEdit(
|
||||
'hello-api', // You must specify the slug of the product
|
||||
array(
|
||||
'title'=>'A New Title',
|
||||
));
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
### List all products
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->linksList();
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
### List all Payments
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->paymentsList();
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
### Get Details of a Payment using Payment ID
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->paymentDetail('[PAYMENT ID]');
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## Available Functions
|
||||
|
||||
You have these functions to interact with the API:
|
||||
|
||||
* `linksList()` List all products created by authenticated User.
|
||||
* `linkDetail($slug)` Get details of product specified by its unique slug.
|
||||
* `linkCreate(array $link)` Create a new product.
|
||||
* `linkEdit($slug, array $link)` Edit an existing product.
|
||||
* `linkDelete($slug)` Archive a product - Archived producrs cannot be generally accessed by the API. User can still view them on the Dashboard at instamojo.com.
|
||||
* `paymentsList()` List all Payments linked to User's account.
|
||||
* `paymentDetail($payment_id)` Get details of a Payment specified by its unique Payment ID. You may receive the Payment ID via `paymentsList()` or via URL Redirect function or as a part of Webhook data.
|
||||
|
||||
## Product Creation Parameters
|
||||
|
||||
### Required
|
||||
|
||||
* `title` - Title of the product, be concise.
|
||||
* `description` - Describe what your customers will get, you can add terms and conditions and any other relevant information here. Markdown is supported, popular media URLs like Youtube, Flickr are auto-embedded.
|
||||
* `base_price` - Price of the product. This may be 0, if you want to offer it for free.
|
||||
|
||||
### File and Cover Image
|
||||
* `file_upload` - Full path to the file you want to sell. This file will be available only after successful payment.
|
||||
* `cover_image` - Full path to the IMAGE you want to upload as a cover image.
|
||||
|
||||
### Quantity
|
||||
* `quantity` - Set to 0 for unlimited sales. If you set it to say 10, a total of 10 sales will be allowed after which the product will be made unavailable.
|
||||
|
||||
### Post Purchase Note
|
||||
* `note` - A post-purchase note, will only displayed after successful payment. Will also be included in the ticket/ receipt that is sent as attachment to the email sent to buyer. This will not be shown if the payment fails.
|
||||
|
||||
### Event
|
||||
* `start_date` - Date-time when the event is beginning. Format: `YYYY-MM-DD HH:mm`
|
||||
* `end_date` - Date-time when the event is ending. Format: `YYYY-MM-DD HH:mm`
|
||||
* `venue` - Address of the place where the event will be held.
|
||||
* `timezone` - Timezone of the venue. Example: Asia/Kolkata
|
||||
|
||||
### Redirects and Webhooks
|
||||
* `redirect_url` - This can be a Thank-You page on your website. Buyers will be redirected to this page after successful payment.
|
||||
* `webhook_url` - Set this to a URL that can accept POST requests made by Instamojo server after successful payment.
|
||||
* `enable_pwyw` - set this to True, if you want to enable Pay What You Want. Default is False.
|
||||
* `enable_sign` - set this to True, if you want to enable Link Signing. Default is False. For more information regarding this, and to avail this feature write to support at instamojo.com.
|
||||
|
||||
---
|
||||
|
||||
## [Request a Payment](RAP.md)
|
||||
|
||||
---
|
||||
|
||||
## [Refunds](REFUNDS.md)
|
||||
|
||||
---
|
||||
|
||||
Further documentation is available at https://www.instamojo.com/developers/
|
||||
136
vendor/instamojo/instamojo-php/README.md
vendored
Normal file
136
vendor/instamojo/instamojo-php/README.md
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
# Instamojo PHP API [](https://packagist.org/packages/instamojo/instamojo-php) [](https://opensource.org/licenses/MIT)
|
||||
|
||||
Assists you to programmatically create, edit and delete Links on Instamojo in PHP.
|
||||
|
||||
**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](https://instamojo.zendesk.com/hc/en-us/articles/208485675-Test-or-Sandbox-Account)).
|
||||
|
||||
|
||||
```php
|
||||
$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN, 'https://test.instamojo.com/api/1.1/');
|
||||
```
|
||||
|
||||
## Installing via [Composer](https://getcomposer.org/)
|
||||
```bash
|
||||
$ php composer.phar require instamojo/instamojo-php
|
||||
```
|
||||
|
||||
**Note**: If you're not using Composer then directly include the contents of `src` directory in your project.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN);
|
||||
```
|
||||
|
||||
### Create a new Payment Request
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->paymentRequestCreate(array(
|
||||
"purpose" => "FIFA 16",
|
||||
"amount" => "3499",
|
||||
"send_email" => true,
|
||||
"email" => "foo@example.com",
|
||||
"redirect_url" => "http://www.example.com/handle_redirect.php"
|
||||
));
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you JSON object containing details of the Payment Request that was just created.
|
||||
|
||||
|
||||
### Get the status or details of a Payment Request
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->paymentRequestStatus(['PAYMENT REQUEST ID']);
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you JSON object containing details of the Payment Request and the payments related to it.
|
||||
Key for payments is `'payments'`.
|
||||
|
||||
Here `['PAYMENT REQUEST ID']` is the value of `'id'` key returned by the `paymentRequestCreate()` query.
|
||||
|
||||
|
||||
### Get the status of a Payment related to a Payment Request
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->paymentRequestPaymentStatus(['PAYMENT REQUEST ID'], ['PAYMENT ID']);
|
||||
print_r($response['purpose']); // print purpose of payment request
|
||||
print_r($response['payment']['status']); // print status of payment
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you JSON object containing details of the Payment Request and the payments related to it.
|
||||
Key for payments is `'payments'`.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### Get a list of all Payment Requests
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->paymentRequestsList();
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
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.
|
||||
|
||||
`paymentRequestsList()` also accepts an optional array containing keys `'max_created_at'` , `'min_created_at'`, `'min_modified_at'` and `'max_modified_at'` for filtering the list of Payment Requests. Note that it is not required to pass all of the keys.
|
||||
|
||||
```php
|
||||
$response = $api->paymentRequestsList(array(
|
||||
"max_created_at" => "2015-11-19T10:12:19Z",
|
||||
"min_created_at" => "2015-10-29T12:51:36Z"
|
||||
));
|
||||
```
|
||||
|
||||
For details related to supported datetime format check the documentation: https://www.instamojo.com/developers/request-a-payment-api/#toc-filtering-payment-requests
|
||||
|
||||
## Available Request a Payment Functions
|
||||
|
||||
You have these functions to interact with the Request a Payment API:
|
||||
|
||||
* `paymentRequestCreate(array $payment_request)` Create a new Payment Request.
|
||||
* `paymentRequestStatus($id)` Get details of Payment Request specified by its unique id.
|
||||
* `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.
|
||||
|
||||
## Payment Request Creation Parameters
|
||||
|
||||
### Required
|
||||
* `purpose`: Purpose of the payment request. (max-characters: 30)
|
||||
* `amount`: Amount requested (min-value: 9 ; max-value: 200000)
|
||||
|
||||
### Optional
|
||||
* `buyer_name`: Name of the payer. (max-characters: 100)
|
||||
* `email`: Email of the payer. (max-characters: 75)
|
||||
* `phone`: Phone number of the payer.
|
||||
* `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`)
|
||||
* `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`)
|
||||
* `redirect_url`: set this to a thank-you page on your site. Buyers will be redirected here after successful payment.
|
||||
* `webhook`: set this to a URL that can accept POST requests made by Instamojo server after successful payment.
|
||||
* `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`).
|
||||
|
||||
|
||||
Further documentation is available at https://docs.instamojo.com/v1.1/docs
|
||||
97
vendor/instamojo/instamojo-php/REFUNDS.md
vendored
Normal file
97
vendor/instamojo/instamojo-php/REFUNDS.md
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
## Refunds
|
||||
|
||||
**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](https://instamojo.zendesk.com/hc/en-us/articles/208485675-Test-or-Sandbox-Account)).
|
||||
|
||||
|
||||
```php
|
||||
$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN, 'https://test.instamojo.com/api/1.1/');
|
||||
```
|
||||
|
||||
|
||||
## Installing via [Composer](https://getcomposer.org/)
|
||||
```bash
|
||||
$ php composer.phar require instamojo/instamojo-php
|
||||
```
|
||||
|
||||
**Note**: If you're not using Composer then directly include the contents of `src` directory in your project.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
$api = new Instamojo\Instamojo(API_KEY, AUTH_TOKEN);
|
||||
```
|
||||
|
||||
### Create a new Refund
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->refundCreate(array(
|
||||
'payment_id'=>'MOJO5c04000J30502939',
|
||||
'type'=>'QFL',
|
||||
'body'=>'Customer is not satified.'
|
||||
));
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you JSON object containing details of the Refund that was just created.
|
||||
|
||||
|
||||
### Get the details of a Refund
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->refundDetail('[REFUND ID]');
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you JSON object containing details of the Refund.
|
||||
|
||||
Here `['REFUND ID']` is the value of `'id'` key returned by the `refundCreate()` query.
|
||||
|
||||
|
||||
### Get a list of all Refunds
|
||||
|
||||
```php
|
||||
try {
|
||||
$response = $api->refundsList();
|
||||
print_r($response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
print('Error: ' . $e->getMessage());
|
||||
}
|
||||
```
|
||||
|
||||
This will give you an array containing Refunds created so far.
|
||||
|
||||
## Available Refund Functions
|
||||
|
||||
You have these functions to interact with the Refund API:
|
||||
|
||||
* `refundCreate(array $refund)` Create a new Refund.
|
||||
* `refundDetail($id)` Get details of Refund specified by its unique id.
|
||||
* `refundsList()` Get a list of all Refunds.
|
||||
|
||||
## Refund Creation Parameters
|
||||
|
||||
### Required
|
||||
* `payment_id`: Payment ID for which Refund is being requested.
|
||||
* `type`: A three letter short-code to identify the type of the refund. Check the
|
||||
REST docs for more info on the allowed values.
|
||||
* `body`: Additional explanation related to why this refund is being requested.
|
||||
|
||||
### Optional
|
||||
* `refund_amount`: This field can be used to specify the refund amount. For instance, you
|
||||
may want to issue a refund for an amount lesser than what was paid. If
|
||||
this field is not provided then the total transaction amount is going to
|
||||
be used.
|
||||
|
||||
Further documentation is available at https://docs.instamojo.com/v1.1/docs
|
||||
28
vendor/instamojo/instamojo-php/composer.json
vendored
Normal file
28
vendor/instamojo/instamojo-php/composer.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "instamojo/instamojo-php",
|
||||
"type": "library",
|
||||
"description": "This is composer wrapper for instamojo-php",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/instamojo/instamojo-php/",
|
||||
"keywords": ["instamojo", "php", "api", "wrapper"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Instamojo and contributors",
|
||||
"email": "dev@instamojo.com",
|
||||
"homepage": "https://github.com/instamojo/instamojo-php/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Instamojo\\": "src/"
|
||||
}
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/instamojo/instamojo-php/issues",
|
||||
"docs": "https://github.com/instamojo/instamojo-php/",
|
||||
"email": "support@instamojo.com"
|
||||
}
|
||||
}
|
||||
386
vendor/instamojo/instamojo-php/src/Instamojo.php
vendored
Normal file
386
vendor/instamojo/instamojo-php/src/Instamojo.php
vendored
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
|
||||
namespace Instamojo;
|
||||
|
||||
class Instamojo {
|
||||
const version = '1.1';
|
||||
|
||||
protected $curl;
|
||||
protected $endpoint = 'https://www.instamojo.com/api/1.1/';
|
||||
protected $api_key = null;
|
||||
protected $auth_token = null;
|
||||
|
||||
/**
|
||||
* @param string $api_key
|
||||
* @param string $auth_token is available on the d
|
||||
* @param string $endpoint can be set if you are working on an alternative server.
|
||||
* @return array AuthToken object.
|
||||
*/
|
||||
public function __construct($api_key, $auth_token=null, $endpoint=null)
|
||||
{
|
||||
$this->api_key = (string) $api_key;
|
||||
$this->auth_token = (string) $auth_token;
|
||||
if(!is_null($endpoint)){
|
||||
$this->endpoint = (string) $endpoint;
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if(!is_null($this->curl)) {
|
||||
curl_close($this->curl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array headers with Authentication tokens added
|
||||
*/
|
||||
private function build_curl_headers()
|
||||
{
|
||||
$headers = array("X-Api-key: $this->api_key");
|
||||
if($this->auth_token) {
|
||||
$headers[] = "X-Auth-Token: $this->auth_token";
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string adds the path to endpoint with.
|
||||
*/
|
||||
private function build_api_call_url($path)
|
||||
{
|
||||
if (strpos($path, '/?') === false and strpos($path, '?') === false) {
|
||||
return $this->endpoint . $path . '/';
|
||||
}
|
||||
return $this->endpoint . $path;
|
||||
|
||||
}
|
||||
|
||||
private function getParamsArray( $limit , $page )
|
||||
{
|
||||
$params = array();
|
||||
if (!is_null($limit)) {
|
||||
$params['limit'] = $limit;
|
||||
}
|
||||
|
||||
if (!is_null($page)) {
|
||||
$params['page'] = $page;
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method ('GET', 'POST', 'DELETE', 'PATCH')
|
||||
* @param string $path whichever API path you want to target.
|
||||
* @param array $data contains the POST data to be sent to the API.
|
||||
* @return array decoded json returned by API.
|
||||
*/
|
||||
private function api_call($method, $path, array $data=null)
|
||||
{
|
||||
$path = (string) $path;
|
||||
$method = (string) $method;
|
||||
$data = (array) $data;
|
||||
$headers = $this->build_curl_headers();
|
||||
$request_url = $this-> build_api_call_url($path);
|
||||
|
||||
$options = array();
|
||||
$options[CURLOPT_HTTPHEADER] = $headers;
|
||||
$options[CURLOPT_RETURNTRANSFER] = true;
|
||||
|
||||
if($method == 'POST') {
|
||||
$options[CURLOPT_POST] = 1;
|
||||
$options[CURLOPT_POSTFIELDS] = http_build_query($data);
|
||||
} else if($method == 'DELETE') {
|
||||
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
|
||||
} else if($method == 'PATCH') {
|
||||
$options[CURLOPT_POST] = 1;
|
||||
$options[CURLOPT_POSTFIELDS] = http_build_query($data);
|
||||
$options[CURLOPT_CUSTOMREQUEST] = 'PATCH';
|
||||
} else if ($method == 'GET' or $method == 'HEAD') {
|
||||
if (!empty($data)) {
|
||||
/* Update URL to container Query String of Paramaters */
|
||||
$request_url .= '?' . http_build_query($data);
|
||||
}
|
||||
}
|
||||
// $options[CURLOPT_VERBOSE] = true;
|
||||
$options[CURLOPT_URL] = $request_url;
|
||||
$options[CURLOPT_SSL_VERIFYPEER] = true;
|
||||
$options[CURLOPT_CAINFO] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacert.pem';
|
||||
|
||||
$this->curl = curl_init();
|
||||
$setopt = curl_setopt_array($this->curl, $options);
|
||||
$response = curl_exec($this->curl);
|
||||
$headers = curl_getinfo($this->curl);
|
||||
|
||||
$error_number = curl_errno($this->curl);
|
||||
$error_message = curl_error($this->curl);
|
||||
$response_obj = json_decode($response, true);
|
||||
|
||||
if($error_number != 0){
|
||||
if($error_number == 60){
|
||||
throw new \Exception("Something went wrong. cURL raised an error with number: $error_number and message: $error_message. " .
|
||||
"Please check http://stackoverflow.com/a/21114601/846892 for a fix." . PHP_EOL);
|
||||
}
|
||||
else{
|
||||
throw new \Exception("Something went wrong. cURL raised an error with number: $error_number and message: $error_message." . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
if($response_obj['success'] == false) {
|
||||
$message = json_encode($response_obj['message']);
|
||||
throw new \Exception($message . PHP_EOL);
|
||||
}
|
||||
return $response_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string URL to upload file or cover image asynchronously
|
||||
*/
|
||||
public function getUploadUrl()
|
||||
{
|
||||
$result = $this->api_call('GET', 'links/get_file_upload_url', array());
|
||||
return $result['upload_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file_path
|
||||
* @return string JSON returned when the file upload is complete.
|
||||
*/
|
||||
public function uploadFile($file_path)
|
||||
{
|
||||
$upload_url = $this->getUploadUrl();
|
||||
$file_path = realpath($file_path);
|
||||
$file_name = basename($file_path);
|
||||
$ch = curl_init();
|
||||
$data = array('fileUpload' => $this->getCurlValue($file_path, $file_name));
|
||||
curl_setopt($ch, CURLOPT_URL, $upload_url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
return curl_exec($ch);
|
||||
}
|
||||
|
||||
public function getCurlValue($file_path, $file_name, $content_type='')
|
||||
{
|
||||
// http://stackoverflow.com/a/21048702/846892
|
||||
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
|
||||
// See: https://wiki.php.net/rfc/curl-file-upload
|
||||
if (function_exists('curl_file_create')) {
|
||||
return curl_file_create($file_path, $content_type, $file_name);
|
||||
}
|
||||
|
||||
// Use the old style if using an older version of PHP
|
||||
$value = "@{$file_path};filename=$file_name";
|
||||
if ($content_type) {
|
||||
$value .= ';type=' . $content_type;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads any file or cover image mentioned in $link and
|
||||
* updates it with the json required by the API.
|
||||
* @param array $link
|
||||
* @return array $link updated with uploaded file information if applicable.
|
||||
*/
|
||||
public function uploadMagic(array $link)
|
||||
{
|
||||
if(!empty($link['file_upload'])) {
|
||||
$file_upload_json = $this->uploadFile($link['file_upload']);
|
||||
$link['file_upload_json'] = $file_upload_json;
|
||||
unset($link['file_upload']);
|
||||
}
|
||||
if(!empty($link['cover_image'])) {
|
||||
$cover_image_json = $this->uploadFile($link['cover_image']);
|
||||
$link['cover_image_json'] = $cover_image_json;
|
||||
unset($link['cover_image']);
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate using username and password of a user.
|
||||
* Automatically updates the auth_token value.
|
||||
* @param array $args contains username=>USERNAME and password=PASSWORD
|
||||
* @return array AuthToken object.
|
||||
*/
|
||||
public function auth(array $args)
|
||||
{
|
||||
$response = $this->api_call('POST', 'auth', $args);
|
||||
$this->auth_token = $response['auth_token']['auth_token'];
|
||||
return $this->auth_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array list of Link objects.
|
||||
*/
|
||||
public function linksList($limit, $path)
|
||||
{
|
||||
$response = $this->api_call('GET', 'links', $this->getParamsArray($limit , $path) );
|
||||
return $response['links'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array single Link object.
|
||||
*/
|
||||
public function linkDetail($slug)
|
||||
{
|
||||
$response = $this->api_call('GET', 'links/' . $slug, array());
|
||||
return $response['link'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array single Link object.
|
||||
*/
|
||||
public function linkCreate(array $link)
|
||||
{
|
||||
if(empty($link['currency'])){
|
||||
$link['currency'] = 'INR';
|
||||
}
|
||||
$link = $this->uploadMagic($link);
|
||||
$response = $this->api_call('POST', 'links', $link);
|
||||
return $response['link'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array single Link object.
|
||||
*/
|
||||
public function linkEdit($slug, array $link)
|
||||
{
|
||||
$link = $this->uploadMagic($link);
|
||||
$response = $this->api_call('PATCH', 'links/' . $slug, $link);
|
||||
return $response['link'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array single Link object.
|
||||
*/
|
||||
public function linkDelete($slug)
|
||||
{
|
||||
$response = $this->api_call('DELETE', 'links/' . $slug, array());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array list of Payment objects.
|
||||
*/
|
||||
public function paymentsList($limit = null, $page = null)
|
||||
{
|
||||
$response = $this->api_call('GET', 'payments', $this->getParamsArray($limit , $page));
|
||||
return $response['payments'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string payment_id as provided by paymentsList() or Instamojo's webhook or redirect functions.
|
||||
* @return array single Payment object.
|
||||
*/
|
||||
public function paymentDetail($payment_id)
|
||||
{
|
||||
$response = $this->api_call('GET', 'payments/' . $payment_id, array());
|
||||
return $response['payment'];
|
||||
}
|
||||
|
||||
|
||||
///// Request a Payment /////
|
||||
|
||||
/**
|
||||
* @param array single PaymentRequest object.
|
||||
* @return array single PaymentRequest object.
|
||||
*/
|
||||
public function paymentRequestCreate(array $payment_request)
|
||||
{
|
||||
$response = $this->api_call('POST', 'payment-requests', $payment_request);
|
||||
return $response['payment_request'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string id as provided by paymentRequestCreate, paymentRequestsList, webhook or redirect.
|
||||
* @return array single PaymentRequest object.
|
||||
*/
|
||||
public function paymentRequestStatus($id)
|
||||
{
|
||||
$response = $this->api_call('GET', 'payment-requests/' . $id, array());
|
||||
return $response['payment_request'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string id as provided by paymentRequestCreate, paymentRequestsList, webhook or redirect.
|
||||
* @param string payment_id as received with the redirection URL or webhook.
|
||||
* @return array single PaymentRequest object.
|
||||
*/
|
||||
public function paymentRequestPaymentStatus($id, $payment_id)
|
||||
{
|
||||
$response = $this->api_call('GET', 'payment-requests/' . $id . '/' . $payment_id, array());
|
||||
return $response['payment_request'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array datetime_limits containing datetime data with keys 'max_created_at', 'min_created_at',
|
||||
* 'min_modified_at' and 'max_modified_at' in ISO 8601 format(optional).
|
||||
* @return array containing list of PaymentRequest objects.
|
||||
* For more information on the allowed date formats check the
|
||||
* docs: https://www.instamojo.com/developers/request-a-payment-api/#toc-filtering-payment-requests
|
||||
*/
|
||||
public function paymentRequestsList( $limit = null , $page = null , $max_created_at = null , $min_created_at = null , $max_modified_at = null , $min_modified_at = null )
|
||||
{
|
||||
$endpoint = 'payment-requests';
|
||||
|
||||
$params = array();
|
||||
if (!is_null($max_created_at)) {
|
||||
$params['max_created_at'] = $max_created_at;
|
||||
}
|
||||
|
||||
if (!is_null($min_created_at)) {
|
||||
$params['min_created_at'] = $min_created_at;
|
||||
}
|
||||
|
||||
if (!is_null($min_modified_at)) {
|
||||
$params['min_modified_at'] = $min_modified_at;
|
||||
}
|
||||
|
||||
if (!is_null($$max_modified_at)) {
|
||||
$params['max_modified_at'] = $max_modified_at;
|
||||
}
|
||||
|
||||
$response = $this->api_call('GET', 'payment-requests', array_merge($params , $this->getParamsArray($limit , $page)));
|
||||
return $response['payment_requests'];
|
||||
}
|
||||
|
||||
|
||||
///// Refunds /////
|
||||
|
||||
/**
|
||||
* @param array single Refund object.
|
||||
* @return array single Refund object.
|
||||
*/
|
||||
public function refundCreate(array $refund)
|
||||
{
|
||||
$response = $this->api_call('POST', 'refunds', $refund);
|
||||
return $response['refund'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string id as provided by refundCreate or refundsList.
|
||||
* @return array single Refund object.
|
||||
*/
|
||||
public function refundDetail($id)
|
||||
{
|
||||
$response = $this->api_call('GET', 'refunds/' . $id, array());
|
||||
return $response['refund'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array containing list of Refund objects.
|
||||
*/
|
||||
public function refundsList($limit, $path)
|
||||
{
|
||||
$response = $this->api_call('GET', 'refunds', $this->getParamsArray($limit, $path));
|
||||
return $response['refunds'];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
3865
vendor/instamojo/instamojo-php/src/cacert.pem
vendored
Normal file
3865
vendor/instamojo/instamojo-php/src/cacert.pem
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user