├── CHANGELOG.md ├── src ├── LaravelPerfectMoneyServiceProvider.php ├── views │ └── perfectmoney.blade.php ├── config │ └── perfectmoney.php └── PerfectMoney.php ├── LICENSE.md ├── CONTRIBUTING.md ├── composer.json └── README.md /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes to `LaravelPerfectMoney` will be documented in this file. 4 | 5 | ## [1.0.0] - 2016-10-12 6 | First stable release. Everything is brand new! 7 | 8 | ## [1.0.1 - 1.0.5] - 2016-10-30 9 | Fixed Bugs 10 | Added generateHash method 11 | Removed MEMO_NOCHANGE option (don't work) -------------------------------------------------------------------------------- /src/LaravelPerfectMoneyServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 19 | __DIR__ . '/../src/config/perfectmoney.php' => config_path('perfectmoney.php'), 20 | ], 'config'); 21 | 22 | 23 | // Views 24 | $this->loadViewsFrom(__DIR__.'/../src/views', 'laravelperfectmoney'); 25 | 26 | $this->publishes([ 27 | __DIR__.'/../src/views' => resource_path('views/vendor/laravelperfectmoney'), 28 | ], 'views'); 29 | } 30 | 31 | /** 32 | * Register any package services. 33 | * 34 | * @return void 35 | */ 36 | public function register() 37 | { 38 | // 39 | } 40 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Charles Assets 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/views/perfectmoney.blade.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | */ 7 | ?> 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | @if($PAYMENT_ID) 16 | 17 | @endif 18 | @if($STATUS_URL) 19 | 20 | @endif 21 | @if($PAYMENT_URL_METHOD) 22 | 23 | @endif 24 | @if( $NOPAYMENT_URL_METHOD ) 25 | 26 | @endif 27 | 28 | @if( $MEMO ) 29 | 30 | @endif 31 | 32 |
-------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/charlesassets/LaravelPerfectMoney). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``. 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ composer test 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "charlesassets/laravel-perfectmoney", 3 | "type": "library", 4 | "description": "Laravel Package for Perfect Money Payments", 5 | "keywords": [ 6 | "PerfectMoney", 7 | "Laravel" 8 | ], 9 | "homepage": "https://github.com/charlesassets/LaravelPerfectMoney", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Charles Patterson", 14 | "email": "charlesassets.com@gmail.com" 15 | }, 16 | { 17 | "name": "Ariama Victor (A.K.A. OVAC BOYA)", 18 | "email": "iamovac@gmail.com" 19 | } 20 | ], 21 | "require": { 22 | "nesbot/carbon": "2.*", 23 | "php" : "^7.1.8 || ^8.0" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit" : "~4.0||~5.0", 27 | "squizlabs/php_codesniffer": "^2.3" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "charlesassets\\LaravelPerfectMoney\\": "src" 32 | } 33 | }, 34 | "autoload-dev": { 35 | "psr-4": { 36 | "charlesassets\\LaravelPerfectMoney\\": "tests" 37 | } 38 | }, 39 | "scripts": { 40 | "test": "phpunit", 41 | "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", 42 | "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" 43 | }, 44 | "extra": { 45 | "branch-alias": { 46 | "dev-master": "1.0-dev" 47 | }, 48 | "laravel": { 49 | "providers": [ 50 | "charlesassets\\LaravelPerfectMoney\\LaravelPerfectMoneyServiceProvider" 51 | ] 52 | } 53 | }, 54 | "config": { 55 | "preferred-install": "dist", 56 | "sort-packages": true, 57 | "optimize-autoloader": true 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Perfect Money 2 | 3 | [![Latest Version on Packagist][ico-version]][link-packagist] 4 | [![Software License][ico-license]](LICENSE.md) 5 | [![Total Downloads][ico-downloads]][link-downloads] 6 | 7 | ## Install 8 | 9 | Via Composer 10 | 11 | ``` bash 12 | $ composer require charlesassets/laravel-perfectmoney 13 | ``` 14 | 15 | Add Provider 16 | 17 | ``` php 18 | charlesassets\LaravelPerfectMoney\LaravelPerfectMoneyServiceProvider::class, 19 | ``` 20 | 21 | Add Aliases 22 | 23 | ``` php 24 | 'PerfectMoney' => charlesassets\LaravelPerfectMoney\PerfectMoney::class, 25 | ``` 26 | 27 | ### Configuration 28 | 29 | Publish Configuration file 30 | ``` 31 | php artisan vendor:publish --provider="charlesassets\LaravelPerfectMoney\LaravelPerfectMoneyServiceProvider" --tag="config" 32 | ``` 33 | 34 | Edit .env 35 | 36 | Add these lines at .env file, follow config/perfectmoney.php for configuration descriptions. 37 | ``` php 38 | PM_ACCOUNTID=100000 39 | PM_PASSPHRASE=your_pm_password 40 | PM_MARCHANTID=U123456 41 | PM_MARCHANT_NAME="My Company" 42 | PM_UNITS=USD 43 | PM_ALT_PASSPHRASE=your_alt_passphrase 44 | PM_PAYMENT_URL=http://example.com/success 45 | PM_PAYMENT_URL_METHOD=null 46 | PM_NOPAYMENT_URL=http://example.com/fail 47 | PM_NOPAYMENT_URL_METHOD=null 48 | PM_STATUS_URL=null 49 | PM_SUGGESTED_MEMO=null 50 | ``` 51 | 52 | ### Customizing views (Optional) 53 | 54 | If you want to customize form, follow these steps. 55 | 56 | ### 1.Publish view 57 | ``` 58 | php artisan vendor:publish --provider="charlesassets\LaravelPerfectMoney\LaravelPerfectMoneyServiceProvider" --tag="views" 59 | ``` 60 | ### 2.Edit your view at /resources/views/vendor/perfectmoney/perfectmoney.php 61 | 62 | ## Usage 63 | 64 | ###Render Shopping Cart Form 65 | 66 | ``` php 67 | PerfectMoney::render(); 68 | ``` 69 | 70 | Sometimes you will need to customize the payment form. Just pass the parameters to render method . 71 | 72 | ``` php 73 | PerfectMoney::render(['PAYMENT_UNITS' => 'EUR'], 'custom_view'); 74 | ``` 75 | 76 | ## API MODULES 77 | ### Get Balance 78 | ``` php 79 | $pm = new PerfectMoney; 80 | $balance = $pm->getBalance(); 81 | 82 | if($balance['status'] == 'success') 83 | { 84 | return $balance['USD']; 85 | } 86 | ``` 87 | 88 | ### Send Money 89 | ``` php 90 | // Required Fields 91 | $amount = 10.00; 92 | $sendTo = 'U1234567'; 93 | 94 | // Optional Fields 95 | $description = 'Optional Description for send money'; 96 | $payment_id = 'Optional_payment_id'; 97 | 98 | $pm = new PerfectMoney; 99 | 100 | // Send Funds with all fields 101 | $sendMoney = $pm->getBalance($amount, $sendTo, $description, $payment_id); 102 | if($sendMoney['status'] == 'success') 103 | { 104 | // Some code here 105 | } 106 | 107 | // Send Funds with required fields 108 | $sendMoney = $pm->getBalance($amount, $sendTo); 109 | if($sendMoney['status'] == 'error') 110 | { 111 | // Payment Failed 112 | return $sendMoney['message']; 113 | } 114 | ``` 115 | 116 | ## Change log 117 | 118 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 119 | 120 | ## Contributing 121 | 122 | Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. 123 | 124 | ## Security 125 | 126 | If you discover any security related issues, please email charlesassets.com@gmail.com instead of using the issue tracker. 127 | 128 | ## Credits 129 | 130 | - [charlesassets][link-author] 131 | - [All Contributors][link-contributors] 132 | 133 | ## License 134 | 135 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 136 | 137 | [ico-version]: https://img.shields.io/packagist/v/charlesassets/laravel-perfectmoney.svg?style=flat-square 138 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 139 | [ico-downloads]: https://img.shields.io/packagist/dt/charlesassets/laravel-perfectmoney.svg?style=flat-square 140 | 141 | [link-packagist]: https://packagist.org/packages/charlesassets/laravel-perfectmoney 142 | [link-downloads]: https://packagist.org/packages/charlesassets/laravel-perfectmoney 143 | [link-author]: https://github.com/charlesassets 144 | [link-contributors]: ../../contributors 145 | -------------------------------------------------------------------------------- /src/config/perfectmoney.php: -------------------------------------------------------------------------------- 1 | env('PM_ACCOUNTID', '100000'), 15 | 16 | /* 17 | |-------------------------------------------------------------------------- 18 | | Your Account Passphrase 19 | |-------------------------------------------------------------------------- 20 | | 21 | | The Account Passphrase (password) used for authentication 22 | | 23 | */ 24 | 25 | 'passphrase' => env('PM_PASSPHRASE', 'your_pm_password'), 26 | 27 | /* 28 | |-------------------------------------------------------------------------- 29 | | Your Marchant Account 30 | |-------------------------------------------------------------------------- 31 | | 32 | | The merchant’s Perfect Money® account to which the payment is to be made. 33 | | 34 | | Example: "U123456" 35 | | 36 | */ 37 | 38 | 'marchant_id' => env('PM_MARCHANTID', 'U123456'), 39 | 40 | 41 | /* 42 | |-------------------------------------------------------------------------- 43 | | Marchant Name 44 | |-------------------------------------------------------------------------- 45 | | 46 | | The name the merchant wishes to have displayed as the Payee on the 47 | | Perfect Money® payment form. 48 | | 49 | | Example: "My company, Inc" 50 | | 51 | */ 52 | 53 | 'marchant_name' => env('PM_MARCHANT_NAME', 'My Company'), 54 | 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Payment Units 59 | |-------------------------------------------------------------------------- 60 | | 61 | | Specifies the units in which payment will be made. 62 | | Currency must correspond to selected account type (at Marchant Account). 63 | | 64 | | Supported: "USD", "EUR", "OAU" 65 | | 66 | */ 67 | 68 | 'units' => env('PM_UNITS', 'USD'), 69 | 70 | 71 | /* 72 | |-------------------------------------------------------------------------- 73 | | Your Account Alternate Passphrase 74 | |-------------------------------------------------------------------------- 75 | | 76 | | The Account Alternate Passphrase entered in your Perfect Money account 77 | | 78 | */ 79 | 80 | 'alternate_passphrase' => env('PM_ALT_PASSPHRASE', 'your_alt_passphrase'), 81 | 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | Payment URL 86 | |-------------------------------------------------------------------------- 87 | | 88 | | The URL to which a form is submitted or to which a hypertext link 89 | | is taken by the buyer’s browser upon successful Perfect Money® payment 90 | | to the merchant. This is the buyer’s normal return path into 91 | | the merchant’s shopping cart system. This URL can specify a secure 92 | | protocol such as https. 93 | | 94 | */ 95 | 96 | 'payment_url' => env('PM_PAYMENT_URL', 'http://example.com/success'), 97 | 98 | /* 99 | |-------------------------------------------------------------------------- 100 | | Payment URL Method (Optional) 101 | |-------------------------------------------------------------------------- 102 | | 103 | | This field controls how the value for the PAYMENT_URL field is used. 104 | | 105 | | Supported: null, "POST", "GET", "LINK" 106 | | 107 | */ 108 | 109 | 'payment_url_method' => env('PM_PAYMENT_URL_METHOD', null), 110 | 111 | 112 | /* 113 | |-------------------------------------------------------------------------- 114 | | NoPayment URL 115 | |-------------------------------------------------------------------------- 116 | | 117 | | The URL to which a form is submitted or to which a hypertext link is taken 118 | | by the buyer’s browser upon an unsuccessful or cancelled Perfect Money® 119 | | payment to the merchant. 120 | | 121 | | Note: this URL can be the same as that provided for PAYMENT_URL, 122 | | since status is provided on the form in hidden text fields to distinguish 123 | | between the two payment outcomes. 124 | | 125 | */ 126 | 127 | 'nopayment_url' => env('PM_NOPAYMENT_URL', 'http://example.com/fail'), 128 | 129 | /* 130 | |-------------------------------------------------------------------------- 131 | | NoPayment URL Method (Optional) 132 | |-------------------------------------------------------------------------- 133 | | 134 | | This field controls how the value for the NOPAYMENT_URL field is used 135 | | 136 | | Supported: null, "POST", "GET", "LINK" 137 | | 138 | */ 139 | 140 | 'nopayment_url_method' => env('PM_NOPAYMENT_URL_METHOD', null), 141 | 142 | 143 | /* 144 | |-------------------------------------------------------------------------- 145 | | Marchant Status URL (Optional) 146 | |-------------------------------------------------------------------------- 147 | | 148 | | Marchant Status URL where will be sent the payment details 149 | | If status url not needed then set value as null. 150 | | 151 | | Legal URL types are “mailto:”, “http://”, and “https://”. 152 | | Non-standard port numbers are not supported. 153 | | 154 | */ 155 | 156 | 'status_url' => env('PM_STATUS_URL', null), 157 | 158 | /* 159 | |-------------------------------------------------------------------------- 160 | | Suggested Payment Description (Optional) 161 | |-------------------------------------------------------------------------- 162 | | 163 | | Data for pre-entered MEMO input field 164 | | If description not required, left it null. 165 | | 166 | */ 167 | 168 | 'suggested_memo' => env('PM_SUGGESTED_MEMO', null), 169 | 170 | 171 | ]; 172 | -------------------------------------------------------------------------------- /src/PerfectMoney.php: -------------------------------------------------------------------------------- 1 | ['verify_peer' => false, 'verify_peer_name' => false]]; 37 | 38 | 39 | public function __construct() 40 | { 41 | $this->account_id = config('perfectmoney.account_id'); 42 | $this->passphrase = config('perfectmoney.passphrase'); 43 | $this->alt_passphrase = config('perfectmoney.alternate_passphrase'); 44 | $this->marchant_id = config('perfectmoney.marchant_id'); 45 | } 46 | 47 | /** 48 | * get the balance for the wallet 49 | * 50 | * @return array 51 | */ 52 | public function getBalance() 53 | { 54 | 55 | // Get data from the server 56 | $url = file_get_contents('https://perfectmoney.is/acct/balance.asp?AccountID=' . $this->account_id . '&PassPhrase=' . $this->passphrase, false, stream_context_create($this->ssl_fix)); 57 | if(!$url) 58 | { 59 | return ['status' => 'error', 'message' => 'Connection error']; 60 | } 61 | 62 | // searching for hidden fields 63 | if(!preg_match_all("//", $url, $result, PREG_SET_ORDER)) 64 | { 65 | return ['status' => 'error', 'message' => 'Invalid output']; 66 | } 67 | 68 | // putting data to array (return error, if have any) 69 | $data = []; 70 | foreach($result as $item) 71 | { 72 | if($item[1] == 'ERROR') 73 | { 74 | return ['status' => 'error', 'message' => $item[2]]; 75 | } 76 | else 77 | { 78 | $data['balance'] = [ 79 | 'currency' => $item[1], 80 | 'balance' => $item[2] 81 | ]; 82 | } 83 | } 84 | 85 | $data['status'] = 'success'; 86 | 87 | return $data; 88 | 89 | 90 | } 91 | 92 | /** 93 | * Send Money 94 | * 95 | * @param string $account 96 | * @param double $amount 97 | * @param string $descripion 98 | * @param string $payment_id 99 | * 100 | * @return array 101 | */ 102 | public function sendMoney($account, $amount, $descripion = '', $payment_id = '') 103 | { 104 | 105 | // trying to open URL to process PerfectMoney Spend request 106 | $url = file_get_contents('https://perfectmoney.is/acct/confirm.asp?AccountID=' . urlencode(trim($this->account_id)) . '&PassPhrase=' . urlencode(trim($this->passphrase)) . '&Payer_Account=' . urlencode(trim($this->marchant_id)) . '&Payee_Account=' . urlencode(trim($account)) . '&Amount=' . $amount . (empty($descripion) ? '' : '&Memo=' . urlencode(trim($descripion))) . (empty($payment_id) ? '' : '&PAYMENT_ID=' . urlencode(trim($payment_id))), false, stream_context_create($this->ssl_fix)); 107 | 108 | if(!$url){ 109 | return ['status' => 'error', 'message' => 'Connection error']; 110 | } 111 | 112 | // searching for hidden fields 113 | if(!preg_match_all("//", $url, $result, PREG_SET_ORDER)) 114 | { 115 | return ['status' => 'error', 'message' => 'Invalid output']; 116 | } 117 | 118 | // putting data to array (return error, if have any) 119 | $data = []; 120 | foreach($result as $item) 121 | { 122 | if($item[1] == 'ERROR') 123 | { 124 | return ['status' => 'error', 'message' => $item[2]]; 125 | } 126 | else 127 | { 128 | $data['data'][$item[1]] = $item[2]; 129 | } 130 | } 131 | 132 | 133 | $data['status'] = 'success'; 134 | 135 | return $data; 136 | 137 | } 138 | 139 | /** 140 | * Render form 141 | * 142 | * @param array $data 143 | * 144 | * @return \Illuminate\View\View 145 | */ 146 | public static function render($data = [], $view = 'perfectmoney') 147 | { 148 | 149 | $view_data = [ 150 | 'PAYEE_ACCOUNT' => (isset($data['PAYEE_ACCOUNT']) ? $data['PAYEE_ACCOUNT'] : config('perfectmoney.marchant_id')), 151 | 'PAYEE_NAME' => (isset($data['PAYEE_NAME']) ? $data['PAYEE_NAME'] : config('perfectmoney.marchant_name')), 152 | 'PAYMENT_AMOUNT' => (isset($data['PAYMENT_AMOUNT']) ? $data['PAYMENT_AMOUNT'] : ''), 153 | 'PAYMENT_UNITS' => (isset($data['PAYMENT_UNITS']) ? $data['PAYMENT_UNITS'] : config('perfectmoney.units')), 154 | 'PAYMENT_ID' => (isset($data['PAYMENT_ID']) ? $data['PAYMENT_ID'] : null), 155 | 'PAYMENT_URL' => (isset($data['PAYMENT_URL']) ? $data['PAYMENT_URL'] : config('perfectmoney.payment_url') ), 156 | 'NOPAYMENT_URL' => (isset($data['NOPAYMENT_URL']) ? $data['NOPAYMENT_URL'] : config('perfectmoney.nopayment_url') ), 157 | ]; 158 | 159 | // Status URL 160 | $view_data['STATUS_URL'] = null; 161 | if(config('perfectmoney.status_url') || isset( $data['STATUS_URL'] )) 162 | { 163 | $view_data['STATUS_URL'] = (isset( $data['STATUS_URL']) ? $data['STATUS_URL'] : config('perfectmoney.status_url')); 164 | } 165 | 166 | // Payment URL Method 167 | $view_data['PAYMENT_URL_METHOD'] = null; 168 | if(config('perfectmoney.payment_url_method') || isset($data['PAYMENT_URL_METHOD'])) 169 | { 170 | $view_data['PAYMENT_URL_METHOD'] = (isset( $data['PAYMENT_URL_METHOD'] ) ? $data['PAYMENT_URL_METHOD'] : config('perfectmoney.payment_url_method')); 171 | } 172 | 173 | // No Payment URL Method 174 | $view_data['NOPAYMENT_URL_METHOD'] = null; 175 | if(config('perfectmoney.nopayment_url_method') || isset($data['NOPAYMENT_URL_METHOD'])) 176 | { 177 | $view_data['NOPAYMENT_URL_METHOD'] = (isset( $data['NOPAYMENT_URL_METHOD'] ) ? $data['NOPAYMENT_URL_METHOD'] : config('perfectmoney.nopayment_url_method')); 178 | } 179 | 180 | // Memo 181 | $view_data['MEMO'] = null; 182 | if(config('perfectmoney.suggested_memo') || isset($data['SUGGESTED_MEMO'])) 183 | { 184 | $view_data['MEMO'] = (isset( $data['SUGGESTED_MEMO'] ) ? $data['SUGGESTED_MEMO'] : config('perfectmoney.suggested_memo')); 185 | 186 | } 187 | 188 | // Custom view 189 | if(view()->exists('laravelperfectmoney::' . $view)){ 190 | return view('laravelperfectmoney::' . $view, $view_data); 191 | } 192 | 193 | 194 | // Default view 195 | return view('laravelperfectmoney::perfectmoney', $view_data); 196 | } 197 | 198 | 199 | /** 200 | * This script demonstrates querying account history 201 | * using PerfectMoney API interface. 202 | * 203 | * @param int $start_day 204 | * @param int $start_month 205 | * @param int $end_year 206 | * @param int $end_day 207 | * @param int $end_month 208 | * @param int $end_year 209 | * 210 | * @return array 211 | */ 212 | public function getHistory($start_day = null, $start_month = null, $start_year = null, $end_day = null, $end_month = null, $end_year = null, $data = []) 213 | { 214 | 215 | $start_day = ($start_day ? $start_day : Carbon::now()->subYear(1)->day); 216 | $start_month = ($start_month ? $start_month : Carbon::now()->subYear(1)->month); 217 | $start_year = ($start_year ? $start_year : Carbon::now()->subYear(1)->year); 218 | $end_day = ($end_day ? $end_day : Carbon::now()->day); 219 | $end_month = ($end_month ? $end_month : Carbon::now()->month); 220 | $end_year = ($end_year ? $end_year : Carbon::now()->year); 221 | 222 | 223 | $url = 'https://perfectmoney.is/acct/historycsv.asp?startmonth=' . $start_month . '&startday=' . $start_day . '&startyear=' . $start_year . '&endmonth=' . $end_month . '&endday=' . $end_day . '&endyear=' . $end_year . '&AccountID=' . urlencode(trim($this->account_id)) . '&PassPhrase=' . urlencode(trim($this->passphrase)); 224 | 225 | // Custom Filters 226 | if(isset($data['payment_id'])) 227 | { 228 | $url .= '&payment_id=' . $data['payment_id']; 229 | } 230 | 231 | // Custom Filters 232 | if(isset($data['batchfilter'])) 233 | { 234 | $url .= '&batchfilter=' . $data['batchfilter']; 235 | } 236 | 237 | if(isset($data['counterfilter'])) 238 | { 239 | $url .= '&counterfilter=' . $data['counterfilter']; 240 | } 241 | 242 | if(isset($data['metalfilter'])) 243 | { 244 | $url .= '&metalfilter=' . $data['metalfilter']; 245 | } 246 | 247 | if(isset($data['payment_id'])) 248 | { 249 | $url .= '&payment_id=' . $data['payment_id']; 250 | } 251 | 252 | if(isset($data['oldsort']) && in_array(strtolower($data['oldsort']), ['tstamp', 'batch_num', 'metal_name', 'counteraccount_id', 'amount ']) ) 253 | { 254 | $url .= '&oldsort=' . $data['oldsort']; 255 | } 256 | 257 | if(isset($data['paymentsmade']) && $data['paymentsmade'] == true) 258 | { 259 | $url .= '&paymentsmade=1'; 260 | } 261 | 262 | if(isset($data['paymentsmade']) && $data['paymentsmade'] == true) 263 | { 264 | $url .= '&paymentsmade=1'; 265 | } 266 | 267 | if(isset($data['paymentsreceived']) && $data['paymentsreceived'] == true) 268 | { 269 | $url .= '&paymentsreceived=1'; 270 | } 271 | 272 | // Get data from the server 273 | $url = file_get_contents($url, false, stream_context_create($this->ssl_fix)); 274 | if(!$url) 275 | { 276 | return ['status' => 'error', 'message' => 'Connection error']; 277 | } 278 | 279 | if (substr($url, 0, 63) == 'Time,Type,Batch,Currency,Amount,Fee,Payer Account,Payee Account') { 280 | 281 | $lines = explode("\n", $url); 282 | 283 | // Getting table names (Time,Type,Batch,Currency,Amount,Fee,Payer Account,Payee Account) 284 | $rows = explode(",", $lines[0]); 285 | 286 | $return_data = []; 287 | 288 | // Fetching history 289 | $return_data['history'] = []; 290 | for($i=1; $i < count($lines); $i++){ 291 | 292 | // Skip empty lines 293 | if(empty($lines[$i])) 294 | { 295 | break; 296 | } 297 | 298 | // Split line into items 299 | $items = explode(',', $lines[$i]); 300 | 301 | // Get history items 302 | $history_line = []; 303 | foreach($items as $key => $value) 304 | { 305 | $history_line[str_replace(' ', '_', strtolower($rows[$key]))] = $value; 306 | } 307 | 308 | $return_data['history'][] = $history_line; 309 | 310 | } 311 | 312 | $return_data['status'] = 'success'; 313 | 314 | return $return_data; 315 | 316 | } 317 | else 318 | { 319 | return ['status' => 'error', 'message' => $url]; 320 | } 321 | 322 | } 323 | 324 | public function generateHash(Request $request) 325 | { 326 | 327 | $string = ''; 328 | $string .= $request->input('PAYMENT_ID') . ':'; 329 | $string .= $request->input('PAYEE_ACCOUNT') . ':'; 330 | $string .= $request->input('PAYMENT_AMOUNT') . ':'; 331 | $string .= $request->input('PAYMENT_UNITS') . ':'; 332 | $string .= $request->input('PAYMENT_BATCH_NUM') . ':'; 333 | $string .= $request->input('PAYER_ACCOUNT') . ':'; 334 | $string .= strtoupper(md5($this->alt_passphrase)) . ':'; 335 | $string .= $request->input('TIMESTAMPGMT'); 336 | 337 | return strtoupper(md5($string)); 338 | 339 | } 340 | 341 | } 342 | 343 | --------------------------------------------------------------------------------