JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrPKZ +paymentwall-php/composer.jsonnu[{ "name": "paymentwall/paymentwall-php", "description": "Paymentwall PHP Library. Paymentwall is the leading digital payments platform for globally monetizing digital goods and services.", "version": "2.2.4", "type": "library", "homepage": "https://www.paymentwall.com/?source=gh", "keywords": [ "paymentwall", "api", "payments", "carrier billing", "credit cards", "alternative payments", "monetization", "recurring billing", "payment processing" ], "license": "MIT", "authors": [ { "name": "Paymentwall Team", "email": "devsupport@paymentwall.com" } ], "require": { "php": ">=5.2", "ext-curl": "*", "ext-json": "*" }, "require-dev": { "behat/behat": "2.4.*@stable" }, "scripts": { "test": [ "@composer install", "vendor/behat/behat/bin/behat" ] }, "config": { "bin-dir": "bin/" }, "autoload": { "classmap": ["lib/Paymentwall/"] }, "minimum-stability": "dev" } PKZ=X;=;=paymentwall-php/README.mdnu[# About Paymentwall [Paymentwall](http://paymentwall.com/?source=gh) is the leading digital payments platform for globally monetizing digital goods and services. Paymentwall assists game publishers, dating sites, rewards sites, SaaS companies and many other verticals to monetize their digital content and services. Merchants can plugin Paymentwall's API to accept payments from over 100 different methods including credit cards, debit cards, bank transfers, SMS/Mobile payments, prepaid cards, eWallets, landline payments and others. To sign up for a Paymentwall Merchant Account, [click here](http://paymentwall.com/signup/merchant?source=gh). # Paymentwall PHP Library This library allows developers to use [Paymentwall APIs](http://paymentwall.com/en/documentation/API-Documentation/722?source=gh) (Virtual Currency, Digital Goods featuring recurring billing, and Virtual Cart). To use Paymentwall, all you need to do is to sign up for a Paymentwall Merchant Account so you can setup an Application designed for your site. To open your merchant account and set up an application, you can [sign up here](http://paymentwall.com/signup/merchant?source=gh). # Installation To install the library in your environment, you have several options: 1. Download ZIP Archive: - Download the [ZIP archive](https://github.com/paymentwall/paymentwall-php/archive/master.zip). - Unzip it. - Place it into your project 2. Git Clone: - Use the following command to clone the repository: git clone git://github.com/paymentwall/paymentwall-php.git 3. Composer: - composer require paymentwall/paymentwall-php Then use a code sample below. # Code Samples ## Digital Goods API #### Initializing Paymentwall Using Paymentwall PHP Library: ```php require_once('/path/to/paymentwall-php/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set([ 'api_type' => Paymentwall_Config::API_GOODS, 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); ``` #### Widget Call [Web API details](http://www.paymentwall.com/en/documentation/Digital-Goods-API/710#paymentwall_widget_call_flexible_widget_call) The widget is a payment page hosted by Paymentwall that embeds the entire payment flow: selecting the payment method, completing the billing details, and providing customer support via the Help section. You can redirect the users to this page or embed it via iframe. Below is an example that renders an iframe with Paymentwall Widget. ```php $widget = new Paymentwall_Widget( 'user40012', // id of the end-user who's making the payment 'pw', // widget code, e.g. pw; can be picked inside of your merchant account [ // product details for Flexible Widget Call. To let users select the product on Paymentwall's end, leave this array empty new Paymentwall_Product( 'product301', // id of the product in your system 9.99, // price 'USD', // currency code 'Gold Membership', // product name Paymentwall_Product::TYPE_SUBSCRIPTION, // this is a time-based product; for one-time products, use Paymentwall_Product::TYPE_FIXED and omit the following 3 array elements 1, // duration is 1 Paymentwall_Product::PERIOD_TYPE_MONTH, // month true // recurring ) ], ['email' => 'user@hostname.com'] // additional parameters ); echo $widget->getHtmlCode(); ``` #### Pingback Processing The Pingback is a webhook notifying about a payment being made. Pingbacks are sent via HTTP/HTTPS to your servers. To process pingbacks use the following code: ```php require_once('/path/to/paymentwall-php/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set([ 'api_type' => Paymentwall_Config::API_GOODS, 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); $pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']); if ($pingback->validate(true)) { $productId = $pingback->getProduct()->getId(); if ($pingback->isDeliverable()) { // deliver the product } else if ($pingback->isCancelable()) { // withdraw the product } else if ($pingback->isUnderReview()) { // set "pending" status to order } echo 'OK'; // Paymentwall expects response to be OK, otherwise the pingback will be resent } else { echo $pingback->getErrorSummary(); } ``` ## Virtual Currency API #### Initializing Paymentwall Using Paymentwall PHP Library: ```php require_once('/path/to/paymentwall-php/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set([ 'api_type' => Paymentwall_Config::API_VC, 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); ``` #### Widget Call ```php $widget = new Paymentwall_Widget( 'user40012', // id of the end-user who's making the payment 'p1_1', // widget code, e.g. p1; can be picked inside of your merchant account [], // array of products - leave blank for Virtual Currency API ['email' => 'user@hostname.com'] // additional parameters ); echo $widget->getHtmlCode(); ``` #### Pingback Processing ```php require_once('/path/to/paymentwall-php/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set([ 'api_type' => Paymentwall_Config::API_VC, 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); $pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']); if ($pingback->validate(true)) { $virtualCurrency = $pingback->getVirtualCurrencyAmount(); if ($pingback->isDeliverable()) { // deliver the virtual currency } else if ($pingback->isCancelable()) { // withdraw the virtual currency } else if ($pingback->isUnderReview()) { // set "pending" status to order } echo 'OK'; // Paymentwall expects response to be OK, otherwise the pingback will be resent } else { echo $pingback->getErrorSummary(); } ``` ## Cart API #### Initializing Paymentwall Using Paymentwall PHP Library: ```php require_once('/path/to/paymentwall-php/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set([ 'api_type' => Paymentwall_Config::API_CART, 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); ``` #### Widget Call Stored products call example (when products are stored in Paymentwall): ```php $widget = new Paymentwall_Widget( 'user40012', // id of the end-user who's making the payment 'p1_1', // widget code, e.g. p1; can be picked inside of your merchant account, [ new Paymentwall_Product('product301', 3.33, 'EUR'), // first product in cart new Paymentwall_Product('product607', 7.77, 'EUR') // second product in cart ], ['email' => 'user@hostname.com'] // additional params ); echo $widget->getHtmlCode(); ``` Non-stored products call example (when products are not stored in Paymentwall): ```php $widget = new Paymentwall_Widget( 'user40012', // id of the end-user who's making the payment 'p1_1', // widget code, e.g. p1; can be picked inside of your merchant account, [ new Paymentwall_Product('product301', 3.33, 'EUR', 'Product 1'), // first product in cart new Paymentwall_Product('product607', 7.77, 'EUR', 'Product 2') // second product in cart ], ['email' => 'user@hostname.com', 'flexible_cart_api' => 1] // additional params ); echo $widget->getHtmlCode(); ``` #### Pingback Processing ```php require_once('/path/to/paymentwall-php/lib/paymentwall.php'); Paymentwall_Config::getInstance()->set([ 'api_type' => Paymentwall_Config::API_CART, 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); $pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']); if ($pingback->validate(true)) { $products = $pingback->getProducts(); if ($pingback->isDeliverable()) { // deliver products from the cart } else if ($pingback->isCancelable()) { // withdraw products from the cart } else if ($pingback->isUnderReview()) { // set "pending" status to order } echo 'OK'; // Paymentwall expects response to be OK, otherwise the pingback will be resent } else { echo $pingback->getErrorSummary(); } ``` ## Brick #### Initializing Paymentwall ```php Paymentwall_Config::getInstance()->set([ 'public_key' => 'YOUR_PUBLIC_KEY', 'private_key' => 'YOUR_PRIVATE_KEY' ]); ``` #### Create a one-time token ```php $tokenModel = new Paymentwall_OneTimeToken(); $token = $tokenModel->create([ 'public_key' => Paymentwall_Config::getInstance()->getPublicKey(), 'card[number]' => '4242424242424242', 'card[exp_month]' => '11', 'card[exp_year]' => '19', 'card[cvv]' => '123' ]); // send token to charge via $token->getToken(); ``` #### Charge ```php $charge = new Paymentwall_Charge(); $charge->create([ // if generated via backend //'token' => $token->getToken(), // if generated via brick.js 'token' => $_POST['brick_token'], 'email' => $_POST['email'], 'currency' => 'USD', 'amount' => 10, 'fingerprint' => $_POST['brick_fingerprint'], 'description' => 'Order #123' ]); $response = $charge->getPublicData(); if ($charge->isSuccessful()) { if ($charge->isCaptured()) { // deliver s product } elseif ($charge->isUnderReview()) { // decide on risk charge } } else { $errors = json_decode($response, true); echo $errors['error']['code']; echo $errors['error']['message']; } echo $response; // need for JS communication ``` #### Charge - refund ```php $charge = new Paymentwall_Charge('CHARGE_ID'); $charge->refund(); echo $charge->isRefunded(); ``` #### Subscription ```php $subscription = new Paymentwall_Subscription(); $subscription->create([ // if generated via backend //'token' => $token->getToken(), // if generated via brick.js 'token' => $_POST['brick_token'], 'email' => $_POST['email'], 'currency' => 'USD', 'amount' => 10, 'fingerprint' => $_POST['brick_fingerprint'], 'plan' => 'product_123', 'description' => 'Order #123', 'period' => 'week', 'period_duration' => 2, // if trial, add following parameters 'trial[amount]' => 1, 'trial[currency]' => 'USD', 'trial[period]' => 'month', 'trial[period_duration]' => 1 ]); echo $subscription->getId(); ``` #### Subscription - cancel ```php $subscription = new Paymentwall_Subscription('SUBSCRIPTION_ID'); $subscription->cancel(); echo $subscription->isActive(); ``` ### Signature calculation - Widget ```php $widgetSignatureModel = new Paymentwall_Signature_Widget(); echo $widgetSignatureModel->calculate( [], // widget params 2 // signature version ); ``` ### Signature calculation - Pingback ```php $pingbackSignatureModel = new Paymentwall_Signature_Pingback(); echo $pingbackSignatureModel->calculate( [], // pingback params 1 // signature version ); ``` ## Mobiamo #### Initializing Paymentwall ```php Paymentwall_Config::getInstance()->set([ 'public_key' => 'YOUR_PROJECT_KEY', 'private_key' => 'YOUR_SECRET_KEY' ]); ``` #### Get a token ```php $model = new Paymentwall_Mobiamo(); $tokenParams = [ 'uid' => 'test' ] $response = $model->getToken($tokenParams); if (!empty($response['success'])) { //store this token and expire time (default is 86400s) to use in all next requests //example of success response: [ 'success' => 1, 'token' => 'randomString', 'expire_time' => 86400 ] var_dump($response['token']); var_dump($response['expire_time']); } else { var_dump($response['error']); var_dump($response['code']); } ``` #### Init payment ```php $model = new Paymentwall_Mobiamo(); $initParams = [ 'uid' => 'test', 'amount' => 1, 'currency' => 'GBP', //currency of payment in ISO 4217 format 'country' => 'GB', //country of payment in ISO alpha-2 format 'product_id' => 123, //product id of payment 'product_name' => 'test_product_name', //product name of payment 'msisdn' => '447821677123', //optional - phone number of user in internaltional format 'carrier' => '19', //mandatory in some countries - Given id of user's operator 'mcc' => '262', //optional - mobile country code of user 'mnc' => '007', //optional - mobile netword code of user 'is_recurring' => 1, //optional and only available in some countries - value: 1/0 - determine if this payment is recurring subscription 'period' => 'd', //mandatory if is_recurring = 1 - value: d (day) - w (week) - m (month) - period of the recurring 'period_value' => 1 //mandatory if is_recurring = 1 - value: positive number - value of the recurring period ]; //token returned from get token step above $response = $model->initPayment($token, $initParams); if (!empty($response['success'])) { /** example of success response: [ 'success' => true, 'ref' => 'w118678712', //reference id of payment. 'flow' => 'code', //next flow of this payment. values can be: code/pinless - user send sms contain keyword to shortcode in instructions/ msisdn - user input phone number / redirect - redirect user to redirect_url in intructions 'price' => [ 'amount' => 1, 'currency' => 'GBP', 'formatted' => 'GBP 1.00', 'carriers' => [ 0 => [ 'id' => 19, 'name' => 'O2', ], ], ], 'instructions' => [ 'keyword' => 'test_keyword', //return if flow = code/pinless - sms message content for user to send 'shortcode' => '123456', //return if flow = code/pinless - the number user should send message to 'redirect_url' => 'http://google.com' //return if flow = redirect - url user should be redirected to ] 'product_name' => 'test_product_name', ] */ //Store the parameter ref } else { var_dump($response['error']); var_dump($response['code']); } ``` #### Process payment (Use this request if previous response has flow = code/msisdn) ```php $model = new Paymentwall_Mobiamo(); $processParams = [ 'uid' => 'test', 'ref' => 'w118678712', //reference id returned from init request 'flow' => 'code', //flow returned from init request 'data' => 'ABCDEF' //value can be: code user received after sending message / phone number of user ]; //token returned from get token step above $response = $model->processPayment($token, $processParams); if (!empty($response['success'])) { /** example of success response: [ 'success' => true, 'flow' => 'redirect', //Only return if this payment requires next processing step. values can be: code - user send keyword to shortcode in instructions/ msisdn - user input phone number / redirect - redirect user to redirect_url in intructions / 'instructions' => [ 'keyword' => 'test_keyword', //return if flow = code/pinless - sms message content for user to send 'shortcode' => '123456', //return if flow = code/pinless - the number user should send message to 'redirect_url' => 'http://google.com' //return if flow = redirect - url user should be redirected to ] ] */ } else { var_dump($response['error']); var_dump($response['code']); } ``` #### Get payment info ```php $model = new Paymentwall_Mobiamo(); $getPaymentParams = [ 'uid' => 'test', 'ref' => 'w118678712', //reference id returned from init request ]; //token returned from get token step above $response = $model->processPayment($token, $getPaymentParams); if (!empty($response['success'])) { /** example of success response: [ 'success' => true, 'completed' => true, //value: true/false - indicate this payment was already successfull or not 'amount' => 1, 'currency' => "GBP", 'country' => "GB", 'product_name' => "test_product_name", 'msisdn' => "447821677123", 'ref' => "w118678712" ] */ } else { var_dump($response['error']); var_dump($response['code']); } ```PKZ:'paymentwall-php/features/charge.featurenu[Feature: Charge In order to let users make payments on my website As a developer I want to be able to perform a charge using Brick Scenario: Should be able to create a test charge Given Public key "t_33c1806e0daf60fc31f2167f0e4d59" And Private key "t_85c66c2d7461e8885805f92dfd171c" When test token is retrieved Then charge should be successful Scenario: Should be able to refund a test charge Given Public key "t_33c1806e0daf60fc31f2167f0e4d59" And Private key "t_85c66c2d7461e8885805f92dfd171c" And charge ID "9557984691424639727_test" Then charge should be refunded Scenario: Should not be able to create a test charge with wrong CVV code Given Public key "t_33c1806e0daf60fc31f2167f0e4d59" And Private key "t_85c66c2d7461e8885805f92dfd171c" And CVV code "333" When test token is retrieved Then I see this error message "The transaction was declined. Please use a different card or contact your bank"PKZEaz_JJ)paymentwall-php/features/pingback.featurenu[Feature: Pingback In order to account for Paymentwall payments on my website As a developer I want to be able to validate Paymentwall pingbacks Scenario: check Digital Goods pingback signature v2 with correct signature and correct IP Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Pingback GET parameters "uid=test_user&goodsid=test_product&slength=5&speriod=month&type=0&ref=t123&is_test=1&sign_version=2&sig=754cff93c0eb859f6054bef143ad253c" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "true" And Pingback method "getUserId" should return "test_user" And Pingback method "getProductId" should return "test_product" And Pingback method "getProductPeriodLength" should return "5" And Pingback method "getProductPeriodType" should return "month" And Pingback method "getReferenceId" should return "t123" And Pingback method "isDeliverable" should return "true" And Pingback method "isCancelable" should return "false" Scenario: check Digital Goods pingback signature v2 with correct signature and wrong IP Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Pingback GET parameters "uid=test_user&goodsid=test_product&slength=5&speriod=month&type=0&ref=t123&is_test=1&sign_version=2&sig=754cff93c0eb859f6054bef143ad253c" And Pingback IP address "1.2.3.4" When Pingback is constructed Then Pingback validation result should be "false" Scenario: check Digital Goods pingback signature v2 with wrong signature and correct IP Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Pingback GET parameters "uid=test_user&goodsid=test_product&slength=5&speriod=month&type=0&ref=t123&is_test=1&sign_version=2&sig=754cff93c0eb859f6054bef143ad253cfoo" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "false" Scenario: check Digital Goods negative pingback signature v3 with correct signature and correct IP Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Pingback GET parameters "uid=test_user&goodsid=test_product&slength=-5&speriod=month&type=2&ref=t123&is_test=1&reason=9&sign_version=3&sig=2f67209c3e581313a70de9425efef49f35a74c0cdb7f93051b47e3c097011a71" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "true" And Pingback method "getProductPeriodLength" should return "-5" And Pingback method "getProductPeriodType" should return "month" And Pingback method "isDeliverable" should return "false" And Pingback method "isCancelable" should return "true" Scenario: check Digital Goods negative pingback signature v1 with correct signature Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Pingback GET parameters "uid=test_user&goodsid=test_product&slength=-5&speriod=month&type=2&ref=t123&is_test=1&reason=9&sig=e7b2ff07bc0734c83ee14f32552b1c88" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "true" Scenario: check Virtual Currency pingback signature v1 with correct signature Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Pingback GET parameters "uid=test_user¤cy=1000&type=0&ref=t555&is_test=1&sig=efaacb488ab8ee19321ad513b6908574" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "true" And Pingback method "getVirtualCurrencyAmount" should return "1000" Scenario: check Virtual Currency pingback signature v1 with wrong signature Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Pingback GET parameters "uid=test_user¤cy=1000&type=0&ref=t555&is_test=1&sig=efaacb488ab8ee19321ad513b6908574foo" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "false" Scenario: check Virtual Currency pingback signature v2 with correct signature Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Pingback GET parameters "uid=test_user¤cy=1000&type=0&ref=t555&is_test=1&sign_version=2&sig=5057977f881bed13592bec928f062b31" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "true" And Pingback method "getVirtualCurrencyAmount" should return "1000" Scenario: check Virtual Currency pingback signature v2 with wrong signature Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Pingback GET parameters "uid=test_user¤cy=1000&type=0&ref=t555&is_test=1&sign_version=2&sig=5057977f881bed13592bec928f062b31foo" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "false" Scenario: check Virtual Currency pingback signature v3 with correct signature Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Pingback GET parameters "uid=test_user¤cy=1000&type=0&ref=t555&is_test=1&sign_version=3&sig=a2932c360010e613166ae95ede5a3fa45bfcac10e1dd93715d21b00d684eb0fb" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "true" And Pingback method "getVirtualCurrencyAmount" should return "1000" Scenario: check Virtual Currency pingback signature v3 with wrong signature Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Pingback GET parameters "uid=test_user¤cy=1000&type=0&ref=t555&is_test=1&sign_version=3&sig=a2932c360010e613166ae95ede5a3fa45bfcac10e1dd93715d21b00d684eb0fbfoo" And Pingback IP address "174.36.92.186" When Pingback is constructed Then Pingback validation result should be "false" PKZOa=='paymentwall-php/features/widget.featurenu[Feature: Widget In order to let users make payments on my website As a developer I want to be able to generate HTML code of Paymentwall widgets Scenario: check Digital Goods widget signature v2 with correct secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Widget signature version "2" And Product name "Automatic Test Product Name" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should not contain "It looks like you're not authorized to view this content." And Widget HTML content should contain "Automatic Test Product Name" Scenario: check Digital Goods widget signature v2 with wrong secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "000" And API type "2" And Widget signature version "2" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should contain "It looks like you're not authorized to view this content." Scenario: check Digital Goods widget signature v1 with correct secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Widget signature version "1" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should not contain "It looks like you're not authorized to view this content." Scenario: check Digital Goods widget signature v1 with wrong secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "000" And API type "2" And Widget signature version "1" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should contain "It looks like you're not authorized to view this content." Scenario: check Digital Goods widget signature v3 with correct secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Widget signature version "3" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should not contain "It looks like you're not authorized to view this content." Scenario: check Digital Goods widget signature v3 with wrong secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "000" And API type "2" And Widget signature version "3" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should contain "It looks like you're not authorized to view this content." Scenario: check Digital Goods widget signature v3 with wrong secret key Given Public key "c22f895840bf2391f67a40da64bfed26" And Secret key "a7408723eaf4bfa2e3ac49b3cb695046" And API type "2" And Widget signature version "3" And Product name "Automatic Test Product Name" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should not contain "It looks like you're not authorized to view this content." And Widget HTML content should contain "Automatic Test Product Name" Scenario: check Virtual Currency offer widget signature v2 with correct secret key Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Widget signature version "2" And Widget code "w1" And Language code "en" When Widget is constructed And Widget HTML content is loaded Then Widget URL should contain "/api/?" And Widget HTML content should not contain "It looks like you're not authorized to view this content." And Widget HTML content should contain "by completing offers below" Scenario: check Virtual Currency payment widget signature v2 with correct secret key Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "6274def95b105f1c92d341a8d3bc2e77" And API type "1" And Widget signature version "2" And Widget code "p10" And Language code "en" When Widget is constructed And Widget HTML content is loaded Then Widget URL should contain "/api/ps?" And Widget HTML content should not contain "It looks like you're not authorized to view this content." And Widget HTML content should contain "Select payment method" Scenario: check Virtual Currency widget signature v2 with wrong secret key Given Public key "c10c60d07a2f4549a17902d683eb0b11" And Secret key "000" And API type "1" And Widget signature version "2" When Widget is constructed And Widget HTML content is loaded Then Widget HTML content should contain "It looks like you're not authorized to view this content."PKZx<6paymentwall-php/features/bootstrap/PingbackContext.phpnu[pingbackParameters = null; $this->pingbackIpAddress = null; } /** * @Given /^Pingback GET parameters "([^"]*)"$/ */ public function pingbackGetParameters($parameters) { parse_str($parameters, $this->pingbackParameters); } /** * @Given /^Pingback IP address "([^"]*)"$/ */ public function pingbackIpAddress($ipAddress) { $this->pingbackIpAddress = $ipAddress; } /** * @When /^Pingback is constructed$/ */ public function pingbackIsConstructed() { $this->pingback = new Paymentwall_Pingback($this->pingbackParameters, $this->pingbackIpAddress); } /** * @Then /^Pingback validation result should be "([^"]*)"$/ */ public function pingbackValidationResultShouldBe($value) { $validate = $this->pingback->validate(); if ($validate !== $value) { throw new Exception( 'Pingback Validation returns ' . var_export($validate, true) . (!$validate ? ("\r\nErrors:" . $this->pingback->getErrorSummary()) : '') ); } } /** * @Given /^Pingback method "([^"]*)" should return "([^"]*)"$/ */ public function pingbackMethodShouldReturn($method, $value) { if ($this->pingback->$method() !== $value) { throw new Exception( 'Pingback method ' . $method . ' returned ' . var_export($value, true) ); } } /** * @Transform /^(true|false)$/ */ public function castStringToBoolean($string) { return filter_var($string, FILTER_VALIDATE_BOOLEAN); } }PKZ5paymentwall-php/features/bootstrap/FeatureContext.phpnu[useContext('pingback', new PingbackContext(array())); $this->useContext('widget', new WidgetContext(array())); $this->useContext('charge', new ChargeContext(array())); } /** * @Given /^Public key "([^"]*)"$/ */ public function publicKey($publicKey) { Paymentwall_Base::setAppKey($publicKey); } /** * @Given /^Secret key "([^"]*)"$/ */ public function secretKey($secretKey) { Paymentwall_Base::setSecretKey($secretKey); } /** * @Given /^Private key "([^"]*)"$/ */ public function privateKey($privateKey) { Paymentwall_Config::getInstance()->set(array( 'private_key' => $privateKey )); } /** * @Given /^API type "([^"]*)"$/ */ public function apiType($apiType) { Paymentwall_Base::setApiType($apiType); $this->apiType = $apiType; } } PKZϫ 4paymentwall-php/features/bootstrap/ChargeContext.phpnu[token = NULL; $this->chargeId = NULL; $this->cvv = '123'; } /** * @Given /^CVV code "([^"]*)"$/ */ public function cvvCode($cvvCode) { $this->cvv = $cvvCode; } /** * @Given /^charge ID "([^"]*)"$/ */ public function chargeId($chargeId) { $this->chargeId = $chargeId; } /** * @When /^test token is retrieved$/ */ public function testTokenIsRetrieved() { $tokenModel = new Paymentwall_OneTimeToken(); $this->token = $tokenModel->create($this->getTestDetailsForOneTimeToken())->getToken(); if (strpos($this->token, 'ot_') === FALSE) { throw new Exception($this->token->getPublicData()); } } /** * @Then /^charge should be successful$/ */ public function chargeShouldBeSuccessful() { $charge = $this->getChargeObject(); if (!$charge->isSuccessful()) { throw new Exception($charge->getPublicData()); } } /** * @Then /^charge should be refunded$/ */ public function chargeShouldBeRefunded() { $chargeToBeRefunded = new Paymentwall_Charge($this->chargeId); if (!$chargeToBeRefunded->refund()->isRefunded()) { throw new Exception($chargeToBeRefunded->getPublicData()); } } /** * @Then /^I see this error message "([^"]*)"$/ */ public function iSeeThisErrorMessage($errorMessage = '') { $charge = $this->getChargeObject(); $errors = json_decode($charge->getPublicData(), TRUE); if (strpos($errorMessage, $errors['error']['message']) === FALSE) { throw new Exception($charge->getPublicData()); } } protected function getChargeObject() { $chargeModel = new Paymentwall_Charge(); return $chargeModel->create($this->getTestDetailsForCharge()); } protected function getTestDetailsForCharge() { return array( 'token' => $this->token, 'email' => 'test@user.com', 'currency' => 'USD', 'amount' => 9.99, 'browser_domain' => 'https://www.paymentwall.com', 'browser_ip' => '72.229.28.185', 'description' => 'Test Charge' ); } protected function getTestDetailsForOneTimeToken() { return array_merge( array('public_key' => Paymentwall_Config::getInstance()->getPublicKey()), $this->getTestCardDetails() ); } protected function getTestCardDetails() { return array( 'card[number]' => '4242424242424242', 'card[exp_month]' => '11', 'card[exp_year]' => '19', 'card[cvv]' => $this->cvv ); } }PKZ\??4paymentwall-php/features/bootstrap/WidgetContext.phpnu[productName = 'Test Default Product Name'; $this->widgetSignatureVersion = null; $this->widgetCode = 'p10'; $this->languageCode = null; } protected function getWidgetSignatureVersion() { return $this->widgetSignatureVersion; } protected function getUserId() { return 'test_user'; } protected function getWidgetCode() { return $this->widgetCode; } protected function getLanguageCode() { return $this->languageCode; } protected function getProduct() { switch ($this->getMainContext()->apiType) { case (Paymentwall_Base::API_GOODS): /** * @todo implement subscriptions, trial, no product */ return array( new Paymentwall_Product( 'product301', 9.99, 'USD', $this->productName, Paymentwall_Product::TYPE_FIXED ) ); case (Paymentwall_Base::API_VC): return array(); case (Paymentwall_Base::API_CART): /** * @todo implement custom IDs and prices */ return array(); } } /** * @Given /^Widget signature version "([^"]*)"$/ */ public function widgetSignatureVersion($signatureVersion) { $this->widgetSignatureVersion = $signatureVersion; } /** * @Given /^Widget code "([^"]*)"$/ */ public function widgetCode($widgetCode) { $this->widgetCode = $widgetCode; } /** * @Given /^Language code "([^"]*)"$/ */ public function languageCode($languageCode) { $this->languageCode = $languageCode; } /** * @Given /^Product name "([^"]*)"$/ */ public function productName($productName) { $this->productName = $productName; } /** * @When /^Widget is constructed$/ */ public function widgetIsConstructed() { $this->widget = new Paymentwall_Widget( $this->getUserId(), $this->getWidgetCode(), $this->getProduct(), array( 'email' => 'user@hostname.com', 'sign_version' => $this->getWidgetSignatureVersion(), 'lang' => $this->getLanguageCode() ) ); } /** * @When /^Widget HTML content is loaded$/ */ public function widgetHtmlContentIsLoaded() { $this->widgetHtmlContent = file_get_contents($this->widget->getUrl()); } /** * @Then /^Widget HTML content should not contain "([^"]*)"$/ */ public function widgetHtmlContentShouldNotContain($phrase) { if (strpos($this->widgetHtmlContent, $phrase) !== false) { throw new Exception( 'Widget HTML content contains "' . $phrase . '"' ); } } /** * @Then /^Widget HTML content should contain "([^"]*)"$/ */ public function widgetHtmlContentShouldContain($phrase) { if (strpos($this->widgetHtmlContent, $phrase) === false) { throw new Exception( 'Widget HTML content doesn\'t contain "' . $phrase . '" (URL: ' . $this->widget->getUrl() .')' ); } } /** * @Then /^Widget URL should not contain "([^"]*)"$/ */ public function widgetUrlShouldNotContain($phrase) { if (strpos($this->widget->getUrl(), $phrase) !== false) { throw new Exception( 'Widget URL contains "' . $phrase . '"' ); } } /** * @Then /^Widget URL should contain "([^"]*)"$/ */ public function widgetUrlShouldContain($phrase) { if (strpos($this->widget->getUrl(), $phrase) === false) { throw new Exception( 'Widget URL doesn\'t contain "' . $phrase . '" (URL: ' . $this->widget->getUrl() .')' ); } } }PKZMySAApaymentwall-php/LICENSEnu[The MIT License (MIT) Copyright (c) 2010-2015 Paymentwall, Inc. 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. PKZ؝Spaymentwall-php/.gitignorenu[# Vagrant .vagrant/* Vagrantfile # SublimeText *.sublime-project *.sublime-workspace # Composer composer.phar vendor/ composer.lock # Behat behat*PKZ#paymentwall-php/lib/paymentwall.phpnu[productId = $productId; $this->amount = round($amount, 2); $this->currencyCode = $currencyCode; $this->name = $name; $this->productType = $productType; $this->periodLength = $periodLength; $this->periodType = $periodType; $this->recurring = $recurring; $this->trialProduct = ($productType == Paymentwall_Product::TYPE_SUBSCRIPTION && $recurring) ? $trialProduct : null; } public function getId() { return $this->productId; } public function getAmount() { return $this->amount; } public function getCurrencyCode() { return $this->currencyCode; } public function getName() { return $this->name; } public function getType() { return $this->productType; } public function getPeriodType() { return $this->periodType; } public function getPeriodLength() { return $this->periodLength; } public function isRecurring() { return $this->recurring; } public function getTrialProduct() { return $this->trialProduct; } }PKZ?UTT6paymentwall-php/lib/Paymentwall/ApiObjectInterface.phpnu[id; } public function isTest() { return $this->test; } public function isSuccessful() { return $this->object == self::API_OBJECT_CHARGE; } public function isCaptured() { return $this->captured; } public function isUnderReview() { return $this->risk == 'pending'; } public function isRefunded() { return $this->refunded; } public function setPropertiesFromResponse($response = '') { parent::setPropertiesFromResponse($response); $this->card = new Paymentwall_Card($this->card); } public function getEndpointName() { return self::API_OBJECT_CHARGE; } public function getCard() { return new Paymentwall_Card($this->card); } public function get() { return $this->doApiAction('', 'get'); } public function refund() { return $this->doApiAction('refund'); } public function capture() { return $this->doApiAction('capture'); } public function void() { return $this->doApiAction('void'); } }PKZ +paymentwall-php/lib/Paymentwall/Mobiamo.phpnu[ $this->getConfig()->getPublicKey(), 'ts' => time(), 'sign_version' => Paymentwall_Signature_Abstract::VERSION_TWO ]; $params = array_merge($defaultParams, $params); $params['sign'] = $this->calculateSignature($params); $this->doApiAction('token', 'post', $params); return $this->getProperties(); } public function initPayment($token, $params){ $this->token = $token; $params['key'] = $this->getConfig()->getPublicKey(); $this->doApiAction('init-payment', 'post', $params); return $this->getProperties(); } public function processPayment($token, $params){ $this->token = $token; $params['key'] = $this->getConfig()->getPublicKey(); $this->doApiAction('process-payment', 'post', $params); return $this->getProperties(); } public function getPaymentInfo($token, $params){ $this->token = $token; $params['key'] = $this->getConfig()->getPublicKey(); $this->doApiAction('get-payment', 'post', $params); return $this->getProperties(); } protected function calculateSignature($params = []) { $baseString = ''; $this->ksortMultiDimensional($params); $baseString = $this->prepareParams($params, $baseString); $baseString .= $this->getConfig()->getPrivateKey(); return md5($baseString); } protected function prepareParams($params = [], $baseString = '') { foreach ($params as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $baseString .= $key . '[' . $k . ']' . '=' . $v; } } else { $baseString .= $key . '=' . $value; } } return $baseString; } protected function ksortMultiDimensional(&$params = []) { if (is_array($params)) { ksort($params); foreach ($params as &$p) { if (is_array($p)) { ksort($p); } } } } public function getApiUrl() { if ($this->getEndpointName() === self::API_OBJECT_ONE_TIME_TOKEN && !$this->getConfig()->isTest()) { return Paymentwall_OneTimeToken::GATEWAY_TOKENIZATION_URL; } else { return $this->getApiBaseUrl() . '/' . $this->getEndpointName(); } } protected function doApiAction($action = '', $method = 'post', $params = []) { $actionUrl = $this->getApiUrl() . '/' . $action; $httpAction = new Paymentwall_HttpAction($this, $params, [$this->getApiBaseHeader()]); $this->setPropertiesFromResponse( $method == 'get' ? $httpAction->get($actionUrl) : $httpAction->post($actionUrl) ); return $this; } protected function getApiBaseHeader() { if ($this->token){ return 'token: ' . $this->token; } return ''; } } PKZzEE-paymentwall-php/lib/Paymentwall/ApiObject.phpnu[_id = $id; } } public final function create($params = []) { $httpAction = new Paymentwall_HttpAction($this, $params, [ $this->getApiBaseHeader() ]); $this->setPropertiesFromResponse($httpAction->run()); return $this; } public function __get($property) { return isset($this->properties[$property]) ? $this->properties[$property] : null; } public function getApiUrl() { if ($this->getEndpointName() === self::API_OBJECT_ONE_TIME_TOKEN && !$this->getConfig()->isTest()) { return Paymentwall_OneTimeToken::GATEWAY_TOKENIZATION_URL; } else { return $this->getApiBaseUrl() . $this->getSubPath() . '/' . $this->getEndpointName(); } } /** * Returns raw data about the response that can be presented to the end-user: * success => 0 or 1 * error => * message - human-readable error message * code - error code, see https://www.paymentwall.com/us/documentation/Brick/2968#error * secure => * formHTML - needed to complete 3D Secure step, HTML of the form to be submitted to the user to redirect him to the bank page * * @return array * */ public function _getPublicData() { /*$responseModel = Paymentwall_Response_Factory::get($this->getPropertiesFromResponse()); return $responseModel instanceof Paymentwall_Response_Interface ? $responseModel->process() : '';*/ /** * @todo encapsulate this into Paymentwall_Response_Factory better; right now it returns success=1 for 3ds case */ $response = $this->getPropertiesFromResponse(); $result = []; if (isset($response['type']) && $response['type'] == 'Error') { $result = [ 'success' => 0, 'error' => [ 'message' => $response['error'], 'code' => $response['code'] ] ]; } elseif (!empty($response['secure'])) { $result = [ 'success' => 0, 'secure' => $response['secure'] ]; } elseif ($this->isSuccessful()) { $result['success'] = 1; } else { $result = [ 'success' => 0, 'error' => [ 'message' => 'Internal error' ] ]; } return $result; } /** * @return string json encoded result of ApiObject::getPublicData() */ public function getPublicData() { return json_encode($this->_getPublicData()); } public function getProperties() { return $this->properties; } public function getRawResponseData() { return $this->_rawResponse; } protected function setPropertiesFromResponse($response = '') { if (!empty($response)) { $this->_rawResponse = $response; $this->properties = (array) $this->preparePropertiesFromResponse($response); } else { throw new Exception('Empty response'); } } protected function getSubPath() { return (in_array($this->getEndpointName(), $this->brickSubEndpoints)) ? '/' . self::API_BRICK_SUBPATH : ''; } protected function getPropertiesFromResponse() { return $this->properties; } protected function preparePropertiesFromResponse($string = '') { return json_decode($string, false); } protected function getApiBaseHeader() { return 'X-ApiKey: ' . $this->getPrivateKey(); } protected function doApiAction($action = '', $method = 'post') { $actionUrl = $this->getApiUrl() . '/' . $this->_id . '/' . $action; $httpAction = new Paymentwall_HttpAction($this, ['id' => $this->_id], [ $this->getApiBaseHeader() ]); $this->_responseLogInformation = $httpAction->getResponseLogInformation(); $this->setPropertiesFromResponse( $method == 'get' ? $httpAction->get($actionUrl) : $httpAction->post($actionUrl) ); return $this; } public function getResponseLogInformation() { return $this->_responseLogInformation; } }PKZU0paymentwall-php/lib/Paymentwall/Subscription.phpnu[id; } public function isTrial() { return $this->is_trial; } public function isActive() { return $this->active; } public function isSuccessful() { return $this->object == self::API_OBJECT_SUBSCRIPTION; } public function isExpired() { return $this->expired; } public function getEndpointName() { return self::API_OBJECT_SUBSCRIPTION; } public function get() { return $this->doApiAction('', 'get'); } public function cancel() { return $this->doApiAction('cancel'); } }PKZ.7>*paymentwall-php/lib/Paymentwall/Widget.phpnu[userId = $userId; $this->widgetCode = $widgetCode; $this->products = $products; $this->extraParams = $extraParams; } public function getUrl() { $params = [ 'key' => $this->getPublicKey(), 'uid' => $this->userId, 'widget' => $this->widgetCode ]; $productsNumber = count($this->products); if ($this->getApiType() == Paymentwall_Config::API_GOODS) { if (!empty($this->products)) { if ($productsNumber == 1) { $product = current($this->products); if ($product->getTrialProduct() instanceof Paymentwall_Product) { $postTrialProduct = $product; $product = $product->getTrialProduct(); } $params['amount'] = $product->getAmount(); $params['currencyCode'] = $product->getCurrencyCode(); $params['ag_name'] = $product->getName(); $params['ag_external_id'] = $product->getId(); $params['ag_type'] = $product->getType(); if ($product->getType() == Paymentwall_Product::TYPE_SUBSCRIPTION) { $params['ag_period_length'] = $product->getPeriodLength(); $params['ag_period_type'] = $product->getPeriodType(); if ($product->isRecurring()) { $params['ag_recurring'] = intval($product->isRecurring()); if (isset($postTrialProduct)) { $params['ag_trial'] = 1; $params['ag_post_trial_external_id'] = $postTrialProduct->getId(); $params['ag_post_trial_period_length'] = $postTrialProduct->getPeriodLength(); $params['ag_post_trial_period_type'] = $postTrialProduct->getPeriodType(); $params['ag_post_trial_name'] = $postTrialProduct->getName(); $params['post_trial_amount'] = $postTrialProduct->getAmount(); $params['post_trial_currencyCode'] = $postTrialProduct->getCurrencyCode(); } } } } else { //TODO: $this->appendToErrors('Only 1 product is allowed in flexible widget call'); } } } else if ($this->getApiType() == Paymentwall_Config::API_CART) { $external_ids = []; $prices = []; $currencies = []; $names = []; foreach ($this->products as $product) { $external_ids[] = $product->getId(); $prices[] = $product->amount ?: 0; $currencies[] = $product->currencyCode ?: ''; $names[] = $product->name ?: ''; } $params['external_ids'] = $external_ids; if (!empty($prices)) { $params['prices'] = $prices; } if (!empty($currencies)) { $params['currencies'] = $currencies; } if (array_filter($names)) { $params['names'] = $names; } } $params['sign_version'] = $signatureVersion = $this->getDefaultSignatureVersion(); if (!empty($this->extraParams['sign_version'])) { $signatureVersion = $params['sign_version'] = $this->extraParams['sign_version']; } $params = array_merge($params, $this->extraParams); $widgetSignatureModel = new Paymentwall_Signature_Widget(); $params['sign'] = $widgetSignatureModel->calculate( $params, $signatureVersion ); return $this->getApiBaseUrl() . '/' . $this->buildController($this->widgetCode) . '?' . http_build_query($params); } public function getHtmlCode($attributes = []) { $defaultAttributes = [ 'frameborder' => '0', 'width' => '750', 'height' => '800' ]; $attributes = array_merge($defaultAttributes, $attributes); $attributesQuery = ''; foreach ($attributes as $attr => $value) { $attributesQuery .= ' ' . $attr . '="' . $value . '"'; } return ''; } protected function getDefaultSignatureVersion() { return $this->getApiType() != Paymentwall_Config::API_CART ? Paymentwall_Signature_Abstract::DEFAULT_VERSION : Paymentwall_Signature_Abstract::VERSION_TWO; } protected function buildController($widget = '') { $controller = null; $isPaymentWidget = !preg_match('/^w|s|mw/', $widget); if ($this->getApiType()== Paymentwall_Config::API_VC) { if ($isPaymentWidget) { $controller = self::CONTROLLER_PAYMENT_VIRTUAL_CURRENCY; } } else if ($this->getApiType() == Paymentwall_Config::API_GOODS) { /** * @todo cover case with offer widget for digital goods for non-flexible widget call */ $controller = self::CONTROLLER_PAYMENT_DIGITAL_GOODS; } else { $controller = self::CONTROLLER_PAYMENT_CART; } return $controller; } } PKZo] (paymentwall-php/lib/Paymentwall/Base.phpnu[setLocalApiType($apiType); } public static function setAppKey($appKey = '') { return self::getInstance()->setPublicKey($appKey); } public static function setSecretKey($secretKey = '') { return self::getInstance()->setPrivateKey($secretKey); } }PKZ'!z,paymentwall-php/lib/Paymentwall/Pingback.phpnu[parameters = $parameters; $this->ipAddress = $ipAddress; } public function validate($skipIpWhitelistCheck = false) { $validated = false; if ($this->isParametersValid()) { if ($skipIpWhitelistCheck || $this->isIpAddressValid()) { if ($this->isSignatureValid()) { $validated = true; } else { $this->appendToErrors('Wrong signature'); } } else { $this->appendToErrors('IP address is not whitelisted'); } } else { $this->appendToErrors('Missing parameters'); } return $validated; } public function isSignatureValid() { $signatureParamsToSign = []; if ($this->getApiType() == Paymentwall_Config::API_VC) { $signatureParams = ['uid', 'currency', 'type', 'ref']; } else if ($this->getApiType() == Paymentwall_Config::API_GOODS) { $signatureParams = ['uid', 'goodsid', 'slength', 'speriod', 'type', 'ref']; } else { // API_CART $signatureParams = ['uid', 'goodsid', 'type', 'ref']; $this->parameters['sign_version'] = Paymentwall_Signature_Abstract::VERSION_TWO; } if (empty($this->parameters['sign_version']) || $this->parameters['sign_version'] == Paymentwall_Signature_Abstract::VERSION_ONE) { foreach ($signatureParams as $field) { $signatureParamsToSign[$field] = isset($this->parameters[$field]) ? $this->parameters[$field] : null; } $this->parameters['sign_version'] = Paymentwall_Signature_Abstract::VERSION_ONE; } else { $signatureParamsToSign = $this->parameters; } $pingbackSignatureModel = new Paymentwall_Signature_Pingback(); $signatureCalculated = $pingbackSignatureModel->calculate( $signatureParamsToSign, $this->parameters['sign_version'] ); $signature = isset($this->parameters['sig']) ? $this->parameters['sig'] : null; return $signature == $signatureCalculated; } public function isIpAddressValid() { $ipsWhitelist = [ '174.36.92.186', '174.36.96.66', '174.36.92.187', '174.36.92.192', '174.37.14.28' ]; $rangesWhitelist = [ '216.127.71.0/24' ]; if (in_array($this->ipAddress, $ipsWhitelist)) { return true; } foreach ($rangesWhitelist as $range) { if ($this->isCidrMatched($this->ipAddress, $range)) { return true; } } return false; } public function isCidrMatched($ip, $range) { list($subnet, $bits) = explode('/', $range); $ip = ip2long($ip); $subnet = ip2long($subnet); $mask = -1 << (32 - $bits); $subnet &= $mask; return ($ip & $mask) == $subnet; } public function isParametersValid() { $errorsNumber = 0; if ($this->getApiType() == Paymentwall_Config::API_VC) { $requiredParams = ['uid', 'currency', 'type', 'ref', 'sig']; } else if ($this->getApiType() == Paymentwall_Config::API_GOODS) { $requiredParams = ['uid', 'goodsid', 'type', 'ref', 'sig']; } else { // Cart API $requiredParams = ['uid', 'goodsid', 'type', 'ref', 'sig']; } foreach ($requiredParams as $field) { if (!isset($this->parameters[$field]) || $this->parameters[$field] === '') { $this->appendToErrors('Parameter ' . $field . ' is missing'); $errorsNumber++; } } return $errorsNumber == 0; } public function getParameter($param) { return isset($this->parameters[$param]) ? $this->parameters[$param] : null; } public function getType() { return isset($this->parameters['type']) ? intval($this->parameters['type']) : null; } public function getTypeVerbal() { $typeVerbal = ''; $pingbackTypes = [ self::PINGBACK_TYPE_SUBSCRIPTION_CANCELLATION => 'user_subscription_cancellation', self::PINGBACK_TYPE_SUBSCRIPTION_EXPIRED => 'user_subscription_expired', self::PINGBACK_TYPE_SUBSCRIPTION_PAYMENT_FAILED => 'user_subscription_payment_failed' ]; if (!empty($this->parameters['type'])) { if (array_key_exists($this->parameters['type'], $pingbackTypes)) { $typeVerbal = $pingbackTypes[$this->parameters['type']]; } } return $typeVerbal; } public function getUserId() { return $this->getParameter('uid'); } public function getVirtualCurrencyAmount() { return $this->getParameter('currency'); } public function getProductId() { return $this->getParameter('goodsid'); } public function getProductPeriodLength() { return $this->getParameter('slength'); } public function getProductPeriodType() { return $this->getParameter('speriod'); } public function getProduct() { return new Paymentwall_Product( $this->getProductId(), 0, null, null, $this->getProductPeriodLength() > 0 ? Paymentwall_Product::TYPE_SUBSCRIPTION : Paymentwall_Product::TYPE_FIXED, $this->getProductPeriodLength(), $this->getProductPeriodType() ); } public function getProducts() { $result = []; $productIds = $this->getParameter('goodsid'); if (!empty($productIds) && is_array($productIds)) { foreach ($productIds as $Id) { $result[] = new Paymentwall_Product($Id); } } return $result; } public function getReferenceId() { return $this->getParameter('ref'); } public function getPingbackUniqueId() { return $this->getReferenceId() . '_' . $this->getType(); } public function isDeliverable() { return ( $this->getType() === self::PINGBACK_TYPE_REGULAR || $this->getType() === self::PINGBACK_TYPE_GOODWILL || $this->getType() === self::PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED ); } public function isCancelable() { return ( $this->getType() === self::PINGBACK_TYPE_NEGATIVE || $this->getType() === self::PINGBACK_TYPE_RISK_REVIEWED_DECLINED ); } public function isUnderReview() { return $this->getType() === self::PINGBACK_TYPE_RISK_UNDER_REVIEW; } } PKZCdd*paymentwall-php/lib/Paymentwall/Config.phpnu[apiBaseUrl; } public function setApiBaseUrl($url = '') { $this->apiBaseUrl = $url; } public function getLocalApiType() { return $this->apiType; } public function setLocalApiType($apiType = 0) { $this->apiType = $apiType; } public function getPublicKey() { return $this->publicKey; } public function setPublicKey($key = '') { $this->publicKey = $key; } public function getPrivateKey() { return $this->privateKey; } public function setPrivateKey($key = '') { $this->privateKey = $key; } public function getVersion() { return self::VERSION; } public function isTest() { return strpos($this->getPublicKey(), 't_') === 0; } public function set($config = []) { if (isset($config['api_base_url'])) { $this->setApiBaseUrl($config['api_base_url']); } if (isset($config['api_type'])) { $this->setLocalApiType($config['api_type']); } if (isset($config['public_key'])) { $this->setPublicKey($config['public_key']); } if (isset($config['private_key'])) { $this->setPrivateKey($config['private_key']); } } /** * @return $this Returns class instance. */ public static function getInstance() { if (!isset(self::$instance)) { $className = __CLASS__; self::$instance = new $className; } return self::$instance; } protected function __construct() { } private function __clone() { } } PKZ[ [ .paymentwall-php/lib/Paymentwall/HttpAction.phpnu[setApiObject($object); $this->setApiParams($params); $this->setApiHeaders($headers); } public function getApiObject() { return $this->apiObject; } public function setApiObject(Paymentwall_ApiObject $apiObject) { $this->apiObject = $apiObject; } public function getApiParams() { return $this->apiParams; } public function setApiParams($params = []) { $this->apiParams = $params; } public function getApiHeaders() { return $this->apiHeaders; } public function setApiHeaders($headers = []) { $this->apiHeaders = $headers; } public function run() { $result = null; if ($this->getApiObject() instanceof Paymentwall_ApiObject) { $result = $this->apiObjectPostRequest($this->getApiObject()); } return $result; } public function apiObjectPostRequest(Paymentwall_ApiObject $object) { return $this->request('POST', $object->getApiUrl(), $this->getApiParams(), $this->getApiHeaders()); } public function post($url = '') { return $this->request('POST', $url, $this->getApiParams(), $this->getApiHeaders()); } public function get($url = '') { return $this->request('GET', $url, $this->getApiParams(), $this->getApiHeaders()); } protected function request($httpVerb = '', $url = '', $params = [], $customHeaders = []) { $curl = curl_init(); $headers = [ $this->getLibraryDefaultRequestHeader() ]; if (!empty($customHeaders)) { $headers = array_merge($headers, $customHeaders); } if (!empty($params)) { curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); } // CURL_SSLVERSION_TLSv1_2 is defined in libcurl version 7.34 or later // but unless PHP has been compiled with the correct libcurl headers it // won't be defined in your PHP instance. PHP > 5.5.19 or > 5.6.3 if (! defined('CURL_SSLVERSION_TLSv1_2')) { define('CURL_SSLVERSION_TLSv1_2', 6); } curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HEADER, true); $response = curl_exec($curl); $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $headerSize); $body = substr($response, $headerSize); $this->responseLogInformation = [ 'header' => $header, 'body' => $body, 'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE) ]; curl_close($curl); return $this->prepareResponse($body); } protected function getLibraryDefaultRequestHeader() { return 'User-Agent: Paymentwall PHP Library v. ' . $this->getConfig()->getVersion(); } protected function prepareResponse($string = '') { return preg_replace('/\x{FEFF}/u', '', $string); } public function getResponseLogInformation() { return $this->responseLogInformation; } }PKZXI(paymentwall-php/lib/Paymentwall/Card.phpnu[fields = (array) $details; } public function __get($property) { return isset($this->fields[$property]) ? $this->fields[$property] : null; } public function getToken() { return $this->token; } public function getType() { return $this->type; } public function getAlias() { return $this->last4; } public function getMonthExpirationDate() { return $this->exp_month; } public function getYearExpirationDate() { return $this->exp_year; } }PKZ~0e0paymentwall-php/lib/Paymentwall/OneTimeToken.phpnu[token; } public function isTest() { return $this->test; } public function isActive() { return $this->active; } public function getExpirationTime() { return $this->expires_in; } public function getEndpointName() { return self::API_OBJECT_ONE_TIME_TOKEN; } }PKZ}x6paymentwall-php/lib/Paymentwall/GenerericApiObject.phpnu[api; } public function __construct($type) { $this->api = $type; $this->httpAction = new Paymentwall_HttpAction($this); } /** * Make post request * * @param array $params * @param array $headers * * @return array */ public function post($params = [], $headers = []) { if (empty($params)) { return null; } $this->httpAction->setApiParams($params); $this->httpAction->setApiHeaders(array_merge([$this->getApiBaseHeader()], $headers)); return (array) $this->preparePropertiesFromResponse( $this->httpAction->post( $this->getApiUrl() ) ); } }PKZlmm,paymentwall-php/lib/Paymentwall/Instance.phpnu[getErrors()); } protected function getConfig() { if (!isset($this->config)) { $this->config = Paymentwall_Config::getInstance(); } return $this->config; } protected function getApiBaseUrl() { return $this->getConfig()->getApiBaseUrl(); } protected function getApiType() { return $this->getConfig()->getLocalApiType(); } protected function getPublicKey() { return $this->getConfig()->getPublicKey(); } protected function getPrivateKey() { return $this->getConfig()->getPrivateKey(); } protected function appendToErrors($error = '') { $this->errors[] = $error; } protected function getErrors() { return $this->errors; } }PKZbbMM4paymentwall-php/lib/Paymentwall/Signature/Widget.phpnu[getConfig()->getPrivateKey(); return md5($baseString); } else { self::ksortMultiDimensional($params); $baseString = $this->prepareParams($params, $baseString); $baseString .= $this->getConfig()->getPrivateKey(); if ($version == self::VERSION_TWO) { return md5($baseString); } return hash('sha256', $baseString); } } public function prepareParams($params = [], $baseString = '') { foreach ($params as $key => $value) { if (!isset($value)) { continue; } if (is_array($value)) { foreach ($value as $k => $v) { $baseString .= $key . '[' . $k . ']' . '=' . ($v === false ? '0' : $v); } } else { $baseString .= $key . '=' . ($value === false ? '0' : $value); } } return $baseString; } } PKZy}}6paymentwall-php/lib/Paymentwall/Signature/Pingback.phpnu[prepareParams($params, $baseString); $baseString .= $this->getConfig()->getPrivateKey(); if ($version == self::VERSION_THREE) { return hash('sha256', $baseString); } return md5($baseString); } public function prepareParams($params = [], $baseString = '') { foreach ($params as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $baseString .= $key . '[' . $k . ']' . '=' . $v; } } else { $baseString .= $key . '=' . $value; } } return $baseString; } }PKZ)OF6paymentwall-php/lib/Paymentwall/Signature/Abstract.phpnu[process($params, $version); } protected static function ksortMultiDimensional(&$params = []) { if (is_array($params)) { ksort($params); foreach ($params as &$p) { if (is_array($p)) { self::ksortMultiDimensional($p); } } } } }PKZ$3CC4paymentwall-php/lib/Paymentwall/Response/Success.phpnu[response)) { return $this->wrapInternalError(); } $response = [ 'success' => 1 ]; return json_encode($response); } }PKZfZZ4paymentwall-php/lib/Paymentwall/Response/Factory.phpnu[response = $response; } protected function wrapInternalError() { $response = [ 'success' => 0, 'error' => [ 'message' => 'Internal error' ] ]; return json_encode($response); } }PKZGTT6paymentwall-php/lib/Paymentwall/Response/Interface.phpnu[response)) { return $this->wrapInternalError(); } $response = [ 'success' => 0, 'error' => $this->getErrorMessageAndCode($this->response) ]; return json_encode($response); } public function getErrorMessageAndCode($response) { return [ 'message' => $response['error'], 'code' => $response['code'] ]; } }PKZ +paymentwall-php/composer.jsonnu[PKZ=X;=;=paymentwall-php/README.mdnu[PKZ:'xApaymentwall-php/features/charge.featurenu[PKZEaz_JJ)yEpaymentwall-php/features/pingback.featurenu[PKZOa=='_paymentwall-php/features/widget.featurenu[PKZx<6qpaymentwall-php/features/bootstrap/PingbackContext.phpnu[PKZ5ypaymentwall-php/features/bootstrap/FeatureContext.phpnu[PKZϫ 4"paymentwall-php/features/bootstrap/ChargeContext.phpnu[PKZ\??4 paymentwall-php/features/bootstrap/WidgetContext.phpnu[PKZMySAApaymentwall-php/LICENSEnu[PKZ؝S5paymentwall-php/.gitignorenu[PKZ#paymentwall-php/lib/paymentwall.phpnu[PKZB9+xpaymentwall-php/lib/Paymentwall/Product.phpnu[PKZ?UTT6paymentwall-php/lib/Paymentwall/ApiObjectInterface.phpnu[PKZ3;*Jpaymentwall-php/lib/Paymentwall/Charge.phpnu[PKZ +Mpaymentwall-php/lib/Paymentwall/Mobiamo.phpnu[PKZzEE-paymentwall-php/lib/Paymentwall/ApiObject.phpnu[PKZU0Spaymentwall-php/lib/Paymentwall/Subscription.phpnu[PKZ.7>*Lpaymentwall-php/lib/Paymentwall/Widget.phpnu[PKZo] (zpaymentwall-php/lib/Paymentwall/Base.phpnu[PKZ'!z,paymentwall-php/lib/Paymentwall/Pingback.phpnu[PKZCdd* paymentwall-php/lib/Paymentwall/Config.phpnu[PKZ[ [ .gpaymentwall-php/lib/Paymentwall/HttpAction.phpnu[PKZXI( !paymentwall-php/lib/Paymentwall/Card.phpnu[PKZ~0e0C$paymentwall-php/lib/Paymentwall/OneTimeToken.phpnu[PKZ}x6&paymentwall-php/lib/Paymentwall/GenerericApiObject.phpnu[PKZlmm,*paymentwall-php/lib/Paymentwall/Instance.phpnu[PKZbbMM4h.paymentwall-php/lib/Paymentwall/Signature/Widget.phpnu[PKZy}}63paymentwall-php/lib/Paymentwall/Signature/Pingback.phpnu[PKZ)OF66paymentwall-php/lib/Paymentwall/Signature/Abstract.phpnu[PKZ$3CC4:paymentwall-php/lib/Paymentwall/Response/Success.phpnu[PKZfZZ4;paymentwall-php/lib/Paymentwall/Response/Factory.phpnu[PKZumdd5z>paymentwall-php/lib/Paymentwall/Response/Abstract.phpnu[PKZGTT6C@paymentwall-php/lib/Paymentwall/Response/Interface.phpnu[PKZMl2@paymentwall-php/lib/Paymentwall/Response/Error.phpnu[PK##vC