Skip to content

Commit 295d708

Browse files
committed
update php-lb
1 parent e04926a commit 295d708

5 files changed

Lines changed: 127 additions & 10 deletions

File tree

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Paymentwall_Base::setSecretKey('YOUR_SECRET_KEY'); // available in your Paymentw
4242
```
4343

4444
#### Widget Call
45-
[Web API details](http://www.paymentwall.com/en/documentation/Digital-Goods-API/710#paymentwall_widget_call_flexible_widget_call)
45+
[Web API details](https://docs.paymentwall.com/integration/widget/digital-goods#widget-call)
4646

4747
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.
4848

@@ -91,6 +91,77 @@ if ($pingback->validate()) {
9191
}
9292
```
9393

94+
## Digital Checkout API
95+
96+
#### Initializing Paymentwall
97+
98+
Using Paymentwall PHP Library v2:
99+
```php
100+
require_once('/path/to/paymentwall-php/lib/paymentwall.php');
101+
Paymentwall_Config::getInstance()->set(array(
102+
'api_type' => Paymentwall_Config::API_GOODS,
103+
'public_key' => 'YOUR_PUBLIC_KEY',
104+
'private_key' => 'YOUR_PRIVATE_KEY'
105+
));
106+
```
107+
Using Paymentwall PHP Library v1 (deprecated in v2):
108+
```php
109+
require_once('/path/to/paymentwall-php/lib/paymentwall.php');
110+
Paymentwall_Base::setApiType(Paymentwall_Base::API_GOODS);
111+
Paymentwall_Base::setAppKey('YOUR_APPLICATION_KEY'); // available in your Paymentwall merchant area
112+
Paymentwall_Base::setSecretKey('YOUR_SECRET_KEY'); // available in your Paymentwall merchant area
113+
```
114+
115+
#### Widget Call
116+
[Web API details](https://docs.paymentwall.com/integration/widget/digital-goods#widget-call)
117+
118+
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.
119+
120+
```php
121+
$widget = new Paymentwall_Widget(
122+
'user40012', // id of the end-user who's making the payment
123+
'pw', // widget code, e.g. pw; can be picked inside of your merchant account
124+
array( // product details for Flexible Widget Call. To let users select the product on Paymentwall's end, leave this array empty
125+
new Paymentwall_Product(
126+
'product301', // id of the product in your system
127+
9.99, // price
128+
'USD', // currency code
129+
'Gold Membership', // product name
130+
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
131+
1, // duration is 1
132+
Paymentwall_Product::PERIOD_TYPE_MONTH, // month
133+
true // recurring
134+
)
135+
),
136+
array('email' => 'user@hostname.com') // additional parameters
137+
);
138+
echo $widget->getHtmlCode();
139+
```
140+
141+
#### Pingback Processing
142+
143+
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:
144+
```php
145+
require_once('/path/to/paymentwall-php/lib/paymentwall.php');
146+
Paymentwall_Base::setApiType(Paymentwall_Base::API_CHECKOUT);
147+
Paymentwall_Base::setAppKey('YOUR_APPLICATION_KEY'); // available in your Paymentwall merchant area
148+
Paymentwall_Base::setSecretKey('YOUR_SECRET_KEY'); // available in your Paymentwall merchant area
149+
$pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']);
150+
if ($pingback->validate()) {
151+
$productId = $pingback->getProduct()->getId();
152+
if ($pingback->isDeliverable()) {
153+
// deliver the product
154+
} else if ($pingback->isCancelable()) {
155+
// withdraw the product
156+
} else if ($pingback->isUnderReview()) {
157+
// set "pending" status to order
158+
}
159+
echo 'OK'; // Paymentwall expects response to be OK, otherwise the pingback will be resent
160+
} else {
161+
echo $pingback->getErrorSummary();
162+
}
163+
```
164+
94165
## Virtual Currency API
95166

96167
#### Initializing Paymentwall

lib/Paymentwall/Config.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,43 @@
22

33
class Paymentwall_Config
44
{
5-
const VERSION = '2.0.0';
6-
7-
const API_BASE_URL = 'https://api.paymentwall.com/api';
5+
const VERSION = '2.0.1';
6+
const BASE_URL = 'https://api.paymentwall.com';
87

8+
/**
9+
* @deprecated 2.0.1
10+
*/
11+
const API_BASE_URL = self::BASE_URL . '/api';
912
const API_VC = 1;
1013
const API_GOODS = 2;
1114
const API_CART = 3;
15+
const API_CHECKOUT = 4;
1216

17+
protected $baseUrl = self::BASE_URL;
1318
protected $apiType = self::API_GOODS;
1419
protected $publicKey;
1520
protected $privateKey;
16-
protected $apiBaseUrl = self::API_BASE_URL;
1721

1822
private static $instance;
1923

24+
public function setBaseUrl($url)
25+
{
26+
$this->baseUrl = $url;
27+
}
28+
29+
public function getBaseUrl()
30+
{
31+
return $this->baseUrl;
32+
}
33+
2034
public function getApiBaseUrl()
2135
{
22-
return $this->apiBaseUrl;
36+
return $this->getBaseUrl() . '/api';
2337
}
2438

39+
/**
40+
* @deprecated 2.0.1 Should use setBaseUrl instead
41+
*/
2542
public function setApiBaseUrl($url = '')
2643
{
2744
$this->apiBaseUrl = $url;
@@ -69,9 +86,15 @@ public function isTest()
6986

7087
public function set($config = array())
7188
{
89+
/**
90+
* @deprecated 2.0.1
91+
*/
7292
if (isset($config['api_base_url'])) {
7393
$this->setApiBaseUrl($config['api_base_url']);
7494
}
95+
if (isset($config['base_url'])) {
96+
$this->setBaseUrl($config['base_url']);
97+
}
7598
if (isset($config['api_type'])) {
7699
$this->setLocalApiType($config['api_type']);
77100
}
@@ -84,8 +107,8 @@ public function set($config = array())
84107
}
85108

86109
/**
87-
* @return $this Returns class instance.
88-
*/
110+
* @return $this Returns class instance.
111+
*/
89112
public static function getInstance()
90113
{
91114
if (!isset(self::$instance)) {

lib/Paymentwall/Instance.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ protected function getConfig()
1818
return $this->config;
1919
}
2020

21+
protected function getBaseUrl()
22+
{
23+
return $this->getConfig()->getBaseUrl();
24+
}
25+
2126
protected function getApiBaseUrl()
2227
{
2328
return $this->getConfig()->getApiBaseUrl();

lib/Paymentwall/Pingback.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function isSignatureValid()
6464

6565
$signatureParams = array('uid', 'goodsid', 'slength', 'speriod', 'type', 'ref');
6666

67+
} else if ($this->getApiType() == Paymentwall_Config::API_CHECKOUT) {
68+
$signatureParams = array('uid', 'goodsid', 'slength', 'speriod', 'type', 'ref');
69+
6770
} else { // API_CART
6871

6972
$signatureParams = array('uid', 'goodsid', 'type', 'ref');
@@ -116,6 +119,8 @@ public function isParametersValid()
116119
$requiredParams = array('uid', 'currency', 'type', 'ref', 'sig');
117120
} else if ($this->getApiType() == Paymentwall_Config::API_GOODS) {
118121
$requiredParams = array('uid', 'goodsid', 'type', 'ref', 'sig');
122+
} else if ($this->getApiType() == Paymentwall_Config::API_CHECKOUT) {
123+
$requiredParams = array('uid', 'goodsid', 'type', 'ref', 'sig');
119124
} else { // Cart API
120125
$requiredParams = array('uid', 'goodsid', 'type', 'ref', 'sig');
121126
}

lib/Paymentwall/Widget.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Paymentwall_Widget extends Paymentwall_Instance
44
{
55
const CONTROLLER_PAYMENT_VIRTUAL_CURRENCY = 'ps';
66
const CONTROLLER_PAYMENT_DIGITAL_GOODS = 'subscription';
7+
const CONTROLLER_PAYMENT_CHECKOUT = 'v1/checkout/orders';
78
const CONTROLLER_PAYMENT_CART = 'cart';
89

910
protected $userId;
@@ -28,7 +29,9 @@ public function getUrl()
2829

2930
$productsNumber = count($this->products);
3031

31-
if ($this->getApiType() == Paymentwall_Config::API_GOODS) {
32+
$apiTypes = array(Paymentwall_Config::API_GOODS, Paymentwall_Config::API_CHECKOUT);
33+
34+
if (in_array($this->getApiType(), $apiTypes)) {
3235

3336
if (!empty($this->products)) {
3437

@@ -105,6 +108,14 @@ public function getUrl()
105108
$signatureVersion
106109
);
107110

111+
$baseUrl = '';
112+
113+
if ($this->getApiType() == Paymentwall_Config::API_CHECKOUT) {
114+
$baseUrl = $this->getBaseUrl();
115+
} else {
116+
$baseUrl = $this->getApiBaseUrl();
117+
}
118+
108119
return $this->getApiBaseUrl() . '/' . $this->buildController($this->widgetCode) . '?' . http_build_query($params);
109120
}
110121

@@ -145,10 +156,12 @@ protected function buildController($widget = '')
145156
* @todo cover case with offer widget for digital goods for non-flexible widget call
146157
*/
147158
$controller = self::CONTROLLER_PAYMENT_DIGITAL_GOODS;
159+
} else if ($this->getApiType() == Paymentwall_Config::API_CHECKOUT) {
160+
$controller = self::CONTROLLER_PAYMENT_CHECKOUT;
148161
} else {
149162
$controller = self::CONTROLLER_PAYMENT_CART;
150163
}
151-
164+
152165
return $controller;
153166
}
154167
}

0 commit comments

Comments
 (0)