/
paymentwall.php
126 lines (106 loc) · 3.88 KB
/
paymentwall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @package Donations
* @author RenildoMarcio
* @copyright (c) 2015 A3LBR
*/
namespace IPS\donate\Gateway;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
require_once "paymentwall/Paymentwall.php";
/**
* Paymentwall Gateway
*/
class _paymentwall extends \IPS\donate\Gateway
{
/**
* Gateway URL
*/
public function gatewayURL()
{
return NULL;
}
/**
* Init Paymentwall
*/
protected function initPaymentwall( $app_key='', $secret_key='' )
{
\Paymentwall_Base::setApiType(\Paymentwall_Base::API_GOODS);
\Paymentwall_Base::setAppKey($app_key);
\Paymentwall_Base::setSecretKey($secret_key);
}
/**
* Payment Screen
*/
public function paymentScreen( \IPS\Helpers\Form $form, $member, $donation )
{
/* Get any gateway settings */
$settings = json_decode( $this->settings, TRUE );
/* We need this before continuing */
if( !isset( $settings['api_key'] ) OR !isset( $settings['api_secretkey'] ) OR !isset( $settings['widget_code'] ) )
{
return $form;
}
/* Init paymentwall */
$this->initPaymentwall( $settings['api_key'], $settings['api_secretkey'] );
/* Setup widget */
$productNames[] = \IPS\Member::loggedIn()->language()->get('forum_donation');
$product = new \Paymentwall_Product( "D1", $donation['amount'], $donation['currency'], implode( ',', $productNames ) );
$widget = new \Paymentwall_Widget( \IPS\Member::loggedIn()->member_id, $settings['widget_code'], array( $product ), array( 'goal' => $donation['goal'] ) );
/* Add widget to form */
$form->addHtml( $widget->getHtmlCode() );
return $form;
}
/**
* Process payment fields
*/
public function process( $result=array() )
{
$paymentFields = array( 'member_id' => isset( $result['uid'] ) ? (int) $result['uid'] : 0,
'amount' => $result['amount'],
'currency' => isset( $result['currencyCode'] ) ? $result['currencyCode'] : 0,
'goal' => isset( $result['goal'] ) ? (int) $result['goal'] : 0,
'status' => 1,
'gateway_email' => 'paymentwall',
'gateway_receiver' => 'paymentwall',
'anonymous' => 0,
'anonymous_amount' => 0,
'txn_id' => $result['ref'],
'note' => '',
'fees' => 0
);
return $paymentFields;
}
/**
* Authorize Payment
*/
public function auth( $donation )
{
/* Get any gateway settings */
$settings = json_decode( $this->settings, true );
self::initPaymentwall( $settings['api_key'], $settings['api_secretkey']);
$params = $_GET;
$pingback = new \Paymentwall_Pingback( $params, $_SERVER['REMOTE_ADDR'] );
$result = array();
if ($pingback->validate(true))
{
if ($pingback->isDeliverable())
{
//$result = array( 'id' => $params['id'], 'status' => 'okay', 'amount' => $params['amount'], 'gw_id' => $params['ref'] );
}
elseif ($pingback->isCancelable())
{
}
echo "OK";
}
else
{
echo ($pingback->getErrorSummary());die();
}
return $params;
}
}