This repository was archived by the owner on Feb 26, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnebip.php
158 lines (138 loc) · 4.95 KB
/
Onebip.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Copyright 2022-2023 FOSSBilling
* Copyright 2011-2021 BoxBilling, Inc.
* SPDX-License-Identifier: Apache-2.0
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
*/
class Payment_Adapter_Onebip extends Payment_AdapterAbstract
{
public function init()
{
}
public static function getConfig()
{
return array(
'supports_one_time_payments' => true,
'supports_subscriptions' => false,
'description' => 'Onebip is a system that allows mobile phone subscribers to transfer pre-paid or post-paid credit from their SIM card to another use.',
'logo' => array(
'logo' => 'onebip.png',
'height' => '25px',
'width' => '100px',
),
'form' => array(
'username' => array('email', array(
'label' => 'The email address associated to your Onebip account.',
),
),
'api_key' => array('password', array(
'label' => 'OneBip API key. Stored in OneBip account settings. Used to validate payment notification',
),
),
'logo_url' => array('text', array(
'label' => 'URL to your company logo. The URL of the 360x45-pixel image displayed as your logo in the upper left corner of the Onebip payment pages',
),
),
),
);
}
/**
* Return payment gateway type
* @return string
*/
public function getType()
{
return Payment_AdapterAbstract::TYPE_FORM;
}
/**
* Return payment gateway call url
* @return string
*/
public function getServiceURL()
{
return 'https://www.onebip.com/otms/';
}
/**
* Init call to webservice or return form params
*
* @see http://www.onebip.com/website/docs/Onebip_API.pdf
*/
public function singlePayment(Payment_Invoice $invoice)
{
$data = array();
$data['username'] = $this->getParam('username');
$data['description'] = $invoice->getTitle();
$data['price'] = $invoice->getTotalWithTax() * 100;
$data['currency'] = $invoice->getCurrency();
$data['command'] = 'standard_pay';
$data['item_code'] = $invoice->getId();
$data['return_url'] = $this->getParam('return_url');
$data['notify_url'] = $this->getParam('notify_url');
$data['cancel_url'] = $this->getParam('cancel_url');
$c = $invoice->getBuyer();
$data['customer_email'] = $c->getEmail();
$data['customer_firstname'] = $c->getFirstName();
$data['customer_lastname'] = $c->getLastName();
if($c->getPhone()) {
$data['customer_cell'] = $c->getPhone();
}
if($c->getCountry()) {
$data['customer_country'] = $c->getCountry();
}
if($this->testMode) {
$data['debug'] = 1;
$data['debug_url'] = $this->getParam('notify_url');
}
$data['logo_url'] = $this->getParam('logo_url');
return $data;
}
/**
* Perform recurent payment
*/
public function recurrentPayment(Payment_Invoice $invoice)
{
throw new Payment_Exception('This feature is unimplemented');
}
public function isIpnValid($data, Payment_Invoice $invoice)
{
$ipn = $data['get'];
$server = $data['server'];
if (isset($ipn['hash'])) {
$my_api_key = $this->getParam('api_key');
$basename = basename($server['REQUEST_URI']);
$pos = strrpos($basename, "&hash");
$basename_without_hash = substr($basename, 0, $pos);
$my_hash = md5($my_api_key . $basename_without_hash);
if ($my_hash != $ipn['hash']) {
$this->setOutput('ERROR: Invalid hash code');
return false;
}
}
$this->setOutput('OK');
return true;
}
public function getTransaction($data, Payment_Invoice $invoice)
{
$ipn = $data['get'];
// Onebip parameters:
$payment_id = $ipn['payment_id'];
$country = $ipn['country'];
$currency = $ipn['currency'];
$price = $ipn['price'];
$tax = $ipn['tax'];
$commission = $ipn['commission'];
$amount = $ipn['amount'];
$original_price = $ipn['original_price'];
$original_currency = $ipn['original_currency'];
$tx = new Payment_Transaction();
$tx->setId($payment_id);
$tx->setAmount($original_price / 100);
$tx->setCurrency($original_currency);
$tx->setStatus(Payment_Transaction::STATUS_COMPLETE);
$tx->setType(Payment_Transaction::TXTYPE_PAYMENT);
return $tx;
}
}