Skip to content

Commit

Permalink
added laravel HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
Md Obydullah committed Jul 3, 2022
1 parent b7179f3 commit 0d751c2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 72 deletions.
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# LaraSkrill

[![Latest Stable Version](https://poser.pugx.org/obydul/laraskrill/v/stable)](https://packagist.org/packages/obydul/laraskrill)
[![Latest Unstable Version](https://poser.pugx.org/obydul/laraskrill/v/unstable)](https://packagist.org/packages/obydul/laraskrill)
[![License](https://poser.pugx.org/obydul/laraskrill/license)](https://packagist.org/packages/obydul/laraskrill)
<a rel="nofollow" href="https://twitter.com/obyydul"><img src="https://img.shields.io/twitter/follow/obyydul?label=Follow&style=social"></a>
<a name="introduction"></a>

## Introduction

By using this plugin you can process or refund payments from Skrill in your Laravel application. You may read this article and can see the output of this package. Article link: [Laravel Skrill Payment Gateway Integration with LaraSkrill](https://shouts.dev/articles/laravel-skrill-payment-gateway-integration-with-laraskrill)

Demo Laravel Project: [Skrill integration in Laravel with LaraSkrill](https://github.com/mdobydullah/laravel-skrill-integration-with-laraskrill)

<a name="installation"></a>

## Installation

* Use the following command to install:
Expand All @@ -19,7 +22,7 @@ Demo Laravel Project: [Skrill integration in Laravel with LaraSkrill](https://gi
composer require obydul/laraskrill
```

* Laravel 5.5 uses package auto-discovery, so doesn't require you to manually add the ServiceProvider. If you don't use auto-discovery, add the service provider to your `$providers` array in `config/app.php` file like:
* Laravel 5.5 uses package auto-discovery, so doesn't require you to manually add the ServiceProvider. If you don't use auto-discovery, add the service provider to your `$providers` array in `config/app.php` file like:

```php
Obydul\LaraSkrill\LaraSkrillServiceProvider::class
Expand All @@ -28,6 +31,7 @@ Obydul\LaraSkrill\LaraSkrillServiceProvider::class
Installation completed.

<a name="configuration"></a>

## Configuration

* After installation, create a constructor.
Expand All @@ -42,19 +46,21 @@ public function __construct()
{
// skrill config
$this->skrilRequest = new SkrillRequest();
$this->skrilRequest->pay_to_email = '[email protected]'; // merchant email
$this->skrilRequest->pay_to_email = '[email protected]'; // your merchant email
$this->skrilRequest->return_url = 'RETURN URL';
$this->skrilRequest->cancel_url = 'CANCEL URL';
$this->skrilRequest->logo_url = 'https://i.imgur.com/BYBiIZX.png'; // optional
$this->skrilRequest->logo_url = 'https://cdn.shouts.dev/images/shoutsdev.png'; // optional
$this->skrilRequest->status_url = 'IPN URL or Email';
$this->skrilRequest->status_url2 = 'IPN URL or Email'; // optional
}
```

#### API/MQI password

To make a refund, we need the API/MQI password. In your Skrill account, go to Settings > Developer Settings > Change MQI/API password.

<a name="usage"></a>

## Usage

Following are some ways through which you can access the LaraSkrill provider:
Expand All @@ -76,19 +82,22 @@ $do_refund = $client->doRefund();
```

#### Make a Payment

```php
// create object instance of SkrillRequest
$this->skrilRequest->transaction_id = 'MNPTTX0001'; // generate transaction id
$this->skrilRequest->amount = '10.26';
$this->skrilRequest->currency = 'USD';
$this->skrilRequest->language = 'EN';
$this->skrilRequest->prepare_only = '1';
$this->skrilRequest->merchant_fields = 'site_name, customer_email';
$this->skrilRequest->site_name = 'Your Website';
$this->skrilRequest->customer_email = 'customer@mynotepaper.com';
$this->skrilRequest->customer_email = 'customer@shouts.dev';
$this->skrilRequest->detail1_description = 'Product ID:';
$this->skrilRequest->detail1_text = '101';

// you can also pass your unique transaction id (optional)
$this->skrilRequest->transaction_id = 'SHOUTSTX0001';

// create object instance of SkrillClient
$client = new SkrillClient($this->skrilRequest);
$sid = $client->generateSID(); //return SESSION ID
Expand All @@ -100,10 +109,11 @@ if ($jsonSID != null && $jsonSID->code == "BAD_REQUEST")

// do the payment
$redirectUrl = $client->paymentRedirectUrl($sid); //return redirect url
return Redirect::to($redirectUrl); // redirect user to Skrill payment page
return redirect()->to($redirectUrl); // redirect user to Skrill payment page
```

#### Refund

```php
// Create object instance of SkrillRequest
$prepare_refund_request = new SkrillRequest();
Expand Down Expand Up @@ -134,6 +144,7 @@ dd($do_refund); // response
```

<a name="note"></a>

## Note

#### Table 1: LaraSkrill Config Parameters
Expand All @@ -147,8 +158,9 @@ dd($do_refund); // response
| status_url, refund_status_url | URL to which the transaction details are posted after the payment process is complete. Alternatively, you may specify an email address where the results are sent. If the status_url is omitted, no transaction details are sent | http://example.com/process_payment.php or mailto:[email protected]
| logo_url | The URL of the logo which you would like to appear in the top right of the Skrill page. The logo must be accessible via HTTPS or it will not be shown. | https://www.example.com/logo.jpg (max length: 240) |

#### Checkout Parameters
There are many parameters of Skrill checkout. Please take a look at the page 13. [Skrill Quick Checkout Integration Guide - v7.9](https://www.skrill.com/fileadmin/content/pdf/Skrill_Quick_Checkout_Guide.pdf)
#### Checkout Parameters

There are many parameters of Skrill checkout. Please take a look at the page 13. [Skrill Quick Checkout Integration Guide - v7.9](https://www.skrill.com/fileadmin/content/pdf/Skrill_Quick_Checkout_Guide.pdf)

`Note:` 'pay_to_email', 'return_url', 'cancel_url', 'status_url' and 'logo_url' are already included in the config file. You can add other fields at checkout without these fields.

Expand All @@ -163,27 +175,32 @@ There are many parameters of Skrill checkout. Please take a look at the page 13.
| Field1 | An additional field you can include, containing your own unique parameters. | No | Value1
| Field2 | An additional field you can include, containing your own unique parameters. | No | Value2

More parameters: You can add more fields. Please take a look at the page 24. [Skrill Automated Payments Interface (API) Guide - v2.8](https://www.skrill.com/fileadmin/content/pdf/Skrill_Automated_Payments_Interface_Guide.pdf)
More parameters: You can add more fields. Please take a look at the page 24. [Skrill Automated Payments Interface (API) Guide - v3.0](https://www.skrill.com/fileadmin/content/pdf/Skrill_Automated_Payments_Interface_Guide.pdf)

`Note:` 'action', 'email', 'password', 'status_url' are already included. You can add other fields at refund without these fields.

**Skrill IPN (status_url):** If you want to get data from 'status_url' instead of receiving email, then use this code to your ipn listener: [Skrill IPN by Md. Obydullah](https://gist.github.com/mdobydullah/8b0399c5c6368c05d98239837a20fb19)

<a name="information"></a>

## Information
- [Skrill Quick Checkout Integration Guide](https://www.skrill.com/fileadmin/content/pdf/Skrill_Quick_Checkout_Guide.pdf) - version 7.9
- [Skrill Automated Payments Interface (API) Guide](https://www.skrill.com/fileadmin/content/pdf/Skrill_Automated_Payments_Interface_Guide.pdf) - version 2.8

- [Skrill Quick Checkout Integration Guide](https://www.skrill.com/fileadmin/content/pdf/Skrill_Quick_Checkout_Guide.pdf) - version 8.1
- [Skrill Automated Payments Interface (API) Guide](https://www.skrill.com/fileadmin/content/pdf/Skrill_Automated_Payments_Interface_Guide.pdf) - version 3.0
- Skrill test merchant email: [email protected], [email protected], [email protected]
- MQI/API password and secret word: **mqi: skrill123, secretword: skrill**
- Skrill test card numbers: VISA: **4000001234567890** | MASTERCARD: **5438311234567890** | AMEX: **371234500012340**
- Skrill test card numbers: VISA: **4000001234567890** | MASTERCARD: **5438311234567890**

<a name="license"></a>

## License

The MIT License (MIT). Please see [License File](https://github.com/mdobydullah/laraskrill/blob/master/LICENSE) for more information.

<a name="others"></a>

## Others

`Note:` I've taken the main concept from [skrill-quick](https://github.com/mikicaivosevic/skrill-quick) and thank you, [Mikica Ivosevic](https://github.com/mikicaivosevic).

In case of any issues, kindly create one on the [Issues](https://github.com/mdobydullah/laraskrill/issues) section.
Expand Down
50 changes: 26 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"name": "obydul/laraskrill",
"description": "LaraSkrill is a laravel plugin for processing payments through Skrill.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Md Obydullah",
"email": "[email protected]"
}
],
"require": {},
"autoload": {
"psr-4": {
"Obydul\\LaraSkrill\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Obydul\\LaraSkrill\\LaraSkrillServiceProvider"
]
}
},
"minimum-stability": "dev"
"name": "obydul/laraskrill",
"description": "LaraSkrill is a laravel plugin for processing payments through Skrill.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Md Obydullah",
"email": "[email protected]"
}
],
"require": {
"laravel/framework": "^7.0"
},
"autoload": {
"psr-4": {
"Obydul\\LaraSkrill\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Obydul\\LaraSkrill\\LaraSkrillServiceProvider"
]
}
},
"minimum-stability": "dev"
}
54 changes: 18 additions & 36 deletions src/SkrillClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Obydul\LaraSkrill;

use Illuminate\Support\Facades\Http;

class SkrillClient
{
/** Skrill payment and refund URL */
const APP_URL = 'https://pay.skrill.com';
const PAY_URL = 'https://pay.skrill.com';
const REFUND_URL = 'https://www.skrill.com/app/refund.pl';

/** @var SkrillRequest $request */
Expand All @@ -20,10 +22,8 @@ class SkrillClient
*/
public function __construct(SkrillRequest $request = null)
{
if ($request != null)
$this->request = $request;
else
echo "<h2>Exception, you need to set SkrillRequest!</h2><br>";
if ($request != null) $this->request = $request;
else echo "<h2>Exception, you need to set SkrillRequest!</h2><br>";
}

/**
Expand All @@ -32,16 +32,10 @@ public function __construct(SkrillRequest $request = null)
public function generateSID()
{
// send request to skrill
$ch = curl_init(self::APP_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); //
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request->toArray());
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);

return $response;
return Http::withoutVerifying()
->withOptions(["verify" => false])
->post(self::PAY_URL, $this->request->toArray())
->body();
}

/**
Expand All @@ -53,7 +47,7 @@ public function paymentRedirectUrl($sid = null)
if (!$this->sid) {
$this->sid = $this->generateSID();
}
return self::APP_URL . "?sid={$this->sid}";
return self::PAY_URL . "?sid={$this->sid}";
}

/**
Expand All @@ -65,16 +59,10 @@ public function prepareRefund()
// add required refund fields
$this->request->action = 'prepare';

$ch = curl_init(self::REFUND_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); //
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request->toArray());
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);

return $response;
return Http::withoutVerifying()
->withOptions(["verify" => false])
->post(self::REFUND_URL, $this->request->toArray())
->body();
}

/**
Expand All @@ -86,16 +74,10 @@ public function doRefund()
// add action
$this->request->action = 'refund';

$ch = curl_init(self::REFUND_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); //
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request->toArray());
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);

return $response;
return Http::withoutVerifying()
->withOptions(["verify" => false])
->post(self::REFUND_URL, $this->request->toArray())
->body();
}

/**
Expand Down

0 comments on commit 0d751c2

Please sign in to comment.