Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dcarfixers
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tobin
dcarfixers
Commits
d8fb4adc
Commit
d8fb4adc
authored
6 years ago
by
Jansa Jose
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'local_production'
payment in app See merge request
!61
parents
9c3226f6
b15822f0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
237 additions
and
4 deletions
+237
-4
Webservices.php
application/controllers/Webservices.php
+114
-0
Mechanic_model.php
application/models/Mechanic_model.php
+19
-3
Webservice_model.php
application/models/Webservice_model.php
+104
-1
No files found.
application/controllers/Webservices.php
View file @
d8fb4adc
...
...
@@ -2602,6 +2602,120 @@
$result
=
$this
->
Webservice_model
->
update_user_address
(
$postData
);
echo
json_encode
(
$result
);
exit
;
}
public
function
bulkOrderBooking
(){
header
(
'Content-type:application/json'
);
$headers
=
apache_request_headers
();
if
(
!
isset
(
$headers
[
'Auth'
])
||
empty
(
$headers
[
'Auth'
])){
$respArr
[
'status'
]
=
'error'
;
$respArr
[
'message'
]
=
'Authtoken is Required'
;
echo
json_encode
(
$respArr
);
exit
;
}
$authRes
=
$this
->
Webservice_model
->
get_customer_authtoken
(
$headers
[
'Auth'
]);
if
(
$authRes
[
'status'
]
==
'error'
){
echo
json_encode
(
$authRes
);
exit
;
}
$post
=
file_get_contents
(
"php://input"
);
$postData
=
json_decode
(
$post
,
true
);
$postData
[
'customer_id'
]
=
$authRes
[
'data'
][
'customer_id'
];
$result
=
$this
->
Webservice_model
->
bulkOrderBooking
(
$postData
);
if
(
$result
[
'status'
]
==
'success'
){
$this
->
orderPayNowApi
(
$result
[
'data'
]);
}
echo
json_encode
(
$result
);
exit
;
}
public
function
orderPayNowApi
(
$transId
=
''
){
if
(
empty
(
$transId
)){
$this
->
fail
();
}
$orderData
=
$this
->
Webservice_model
->
getOrderPayDetailsApi
(
$transId
);
if
(
$orderData
[
'status'
]
==
'success'
){
$amount
=
$orderData
[
'data'
]
->
bulk_amount
*
100
;
$callback
=
base_url
()
.
'Webservices/verify_payment_api/'
.
$transId
.
'/2'
;
$postdata
=
array
(
'email'
=>
$orderData
[
'data'
]
->
email
,
'amount'
=>
$amount
,
'reference'
=>
$transId
,
'callback_url'
=>
$callback
);
$this
->
payStackPaymentApi
(
$postdata
);
}
}
public
function
payStackPaymentApi
(
$postdata
=
array
())
{
$url
=
"https://api.paystack.co/transaction/initialize"
;
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
json_encode
(
$postdata
));
//Post Fields
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYHOST
,
0
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
0
);
$headers
=
[
'Authorization: Bearer '
.
PAYSTACK_SECRET_KEY
,
'Content-Type: application/json'
,
];
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$headers
);
$request
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
$result
=
array
();
if
(
$request
)
{
$result
=
json_decode
(
$request
,
true
);
}
$redir
=
$result
[
'data'
][
'authorization_url'
];
header
(
"Location: "
.
$redir
);
}
public
function
verify_payment_api
(
$transId
=
''
,
$payFor
=
'1'
)
{
if
(
empty
(
$transId
)){
$this
->
fail
();
}
$result
=
array
();
$url
=
'https://api.paystack.co/transaction/verify/'
.
$transId
;
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYHOST
,
0
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
0
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
[
'Authorization: Bearer '
.
PAYSTACK_SECRET_KEY
]
);
$request
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
if
(
$request
)
{
$result
=
json_decode
(
$request
,
true
);
$status
=
$this
->
Webservice_model
->
transactionRespApi
(
$transId
,
$result
,
$payFor
);
if
(
$status
){
if
(
$result
){
if
(
$result
[
'data'
]){
if
(
$result
[
'data'
][
'status'
]
==
'success'
){
header
(
"Location:"
.
base_url
(
'Webservices/success/'
.
$transId
.
'/'
.
$payFor
));
}
else
{
header
(
"Location:"
.
base_url
(
'Webservices/fail/'
.
$transId
.
'/'
.
$payFor
));
}
}
else
{
header
(
"Location: "
.
base_url
(
'Webservices/fail/'
.
$transId
.
'/'
.
$payFor
));
}
}
else
{
header
(
"Location: "
.
base_url
(
'Webservices/fail/'
.
$transId
.
'/'
.
$payFor
));
}
}
}
else
{
header
(
"Location: "
.
base_url
(
'Webservices/fail/'
.
$transId
.
'/'
.
$payFor
));
}
}
}
...
...
This diff is collapsed.
Click to expand it.
application/models/Mechanic_model.php
View file @
d8fb4adc
...
...
@@ -183,15 +183,31 @@ class Mechanic_model extends CI_Model {
foreach
(
$mechData
AS
$index
=>
$data
){
$data
[
'distance'
]
=
(
int
)
$data
[
'distance'
];
if
(
empty
(
$data
[
'start_time'
])
||
empty
(
$data
[
'end_time'
])){
$scheduleTiming
=
array
(
'09:00 AM'
,
'10:00 AM'
,
'11:00 AM'
,
'12:00 PM'
,
'01:00 PM'
,
'02:00 PM'
,
'03:00 PM'
,
'04:00 PM'
,
'05:00 PM'
,
'06:00 PM'
);
//$scheduleTiming = array('09:00 AM','10:00 AM','11:00 AM','12:00 PM','01:00 PM',
// '02:00 PM','03:00 PM','04:00 PM','05:00 PM','06:00 PM');
$scheduleTiming
=
array
(
strtotime
(
date
(
'Y-m-d 09:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 10:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 11:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 12:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 13:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 14:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 15:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 16:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 17:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 18:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 19:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 20:00'
))
*
1000
,
strtotime
(
date
(
'Y-m-d 21:00'
))
*
1000
,
);
}
else
{
$endTime
=
strtotime
(
$data
[
'end_time'
]);
$schTime
=
strtotime
(
$data
[
'start_time'
]);
$scheduleTiming
=
array
();
for
(
;
$schTime
<=
(
$endTime
-
3600
)
;
$schTime
+=
3600
){
$scheduleTiming
[]
=
date
(
'h:i A'
,
$schTime
);
//$scheduleTiming[] = date('h:i A',$schTime);
$scheduleTiming
[]
=
$schTime
*
1000
;
}
}
...
...
This diff is collapsed.
Click to expand it.
application/models/Webservice_model.php
View file @
d8fb4adc
...
...
@@ -591,6 +591,26 @@ class Webservice_model extends CI_Model {
return
1
;
}
public
function
transactionRespApi
(
$transId
,
$result
,
$payfor
){
$status
=
0
;
if
(
$result
[
'data'
][
'status'
]
==
'success'
){
$status
=
1
;
}
$odr_status
=
9
;
if
(
$result
[
'data'
][
'status'
]
==
'success'
&&
$payfor
==
'2'
){
$odr_status
=
2
;
}
$bookData
=
$this
->
db
->
get_where
(
'transaction'
,
array
(
'id'
=>
$transId
))
->
row
();
$this
->
db
->
update
(
'transaction'
,
array
(
'transaction_response'
=>
json_encode
(
$result
),
'transaction_reference'
=>
$result
[
'data'
][
'id'
],
'status'
=>
$status
),
array
(
'bulk_bkng_unqId'
=>
$bookData
->
bulk_bkng_unqId
));
if
(
$payfor
==
'2'
){
$this
->
db
->
query
(
"UPDATE orders JOIN transaction ON transaction.booking_id = orders.order_id SET orders.status =
$odr_status
WHERE transaction.bulk_bkng_unqId = '"
.
$bookData
->
bulk_bkng_unqId
.
"'"
);
}
return
1
;
}
public
function
productSearch
(
$postData
,
$start
=
''
,
$per_page
=
''
){
$respArr
=
array
(
'status'
=>
'error'
);
if
(
empty
(
$postData
)){
...
...
@@ -678,7 +698,7 @@ class Webservice_model extends CI_Model {
}
$total
=
0
;
$per_page
=
10
;
$page
=
(
isset
(
$postData
[
'page'
])
&&
$postData
[
'page'
]
!=
1
)
?
$postData
[
'page'
]
:
'1'
;
$page
=
(
isset
(
$postData
[
'page'
])
&&
$postData
[
'page'
]
!=
1
)
?
$postData
[
'page'
]
:
1
;
$page_limit
=
(
$page
-
1
)
*
$per_page
;
$cartSel
=
''
;
...
...
@@ -870,6 +890,68 @@ class Webservice_model extends CI_Model {
return
$respArr
;
}
public
function
bulkOrderBooking
(
$postData
=
array
()){
$respArr
=
array
(
'status'
=>
'error'
);
if
(
count
(
$postData
[
'data'
])
<
0
){
$respArr
[
'message'
]
=
'All Field is required'
;
return
$respArr
;
}
$bulk_flag
=
0
;
$bulkUnqueId
=
''
;
if
((
$bulk_flag
=
count
(
$postData
[
'data'
]))
>
1
){
$bulk_flag
=
1
;
$bulkUnqueId
=
'ORDBK'
.
time
();
}
$transId
=
''
;
foreach
(
$postData
[
'data'
]
as
$orderKey
=>
$orderValue
)
{
$orderValue
[
'customer_id'
]
=
$postData
[
'customer_id'
];
$orderValue
[
'bulkUnqueId'
]
=
$bulkUnqueId
;
$orderValue
[
'bulk_bkng_flag'
]
=
$bulk_flag
;
$transId
=
$this
->
insertOrders
(
$orderValue
);
}
if
(
empty
(
$transId
)){
header
(
"Location:"
.
base_url
(
'Webservices/fail/'
));
}
$respArr
[
'status'
]
=
'success'
;
$respArr
[
'data'
]
=
$transId
;
return
$respArr
;
}
public
function
insertOrders
(
$orderValue
=
array
()){
if
(
empty
(
$orderValue
)){
return
;
}
$squence
=
str_pad
(
rand
(
1111
,
9999
),
4
,
0
,
STR_PAD_LEFT
);
$insertArray
=
array
(
'format_order_id'
=>
'ORD'
.
date
(
'ymd'
)
.
$squence
,
'product_id'
=>
$orderValue
[
'product_id'
],
'customer_id'
=>
$orderValue
[
'customer_id'
],
'address_id'
=>
$orderValue
[
'address_id'
],
'quantity'
=>
$orderValue
[
'quantity'
],
'amount'
=>
$orderValue
[
'total_amount'
]
);
$status
=
$this
->
db
->
insert
(
'orders'
,
$insertArray
);
if
(
!
$status
)
return
;
$insert_id
=
$this
->
db
->
insert_id
();
$insertArray
=
array
(
'customer_id'
=>
$orderValue
[
'customer_id'
],
'booking_id'
=>
$insert_id
,
'payment_for'
=>
'2'
,
'datetime'
=>
date
(
'Y-m-d h:i:s'
),
'amount'
=>
$orderValue
[
'total_amount'
],
'bulk_bkng_flag'
=>
$orderValue
[
'bulk_bkng_flag'
],
'bulk_bkng_unqId'
=>
$orderValue
[
'bulkUnqueId'
],
'bulk_amount'
=>
$orderValue
[
'bulk_amount'
]
);
$this
->
db
->
insert
(
'transaction'
,
$insertArray
);
if
(
!
$status
)
return
;
$insert_id
=
$this
->
db
->
insert_id
();
return
$insert_id
;
}
public
function
getOrderPayDetails
(
$orderId
){
$respArr
=
array
(
'status'
=>
'error'
);
if
(
empty
(
$orderId
)){
...
...
@@ -892,6 +974,27 @@ class Webservice_model extends CI_Model {
return
$respArr
;
}
public
function
getOrderPayDetailsApi
(
$transId
){
$respArr
=
array
(
'status'
=>
'error'
);
if
(
empty
(
$transId
)){
$respArr
[
'message'
]
=
'Order Id is required'
;
return
$respArr
;
}
$result
=
$this
->
db
->
query
(
"SELECT TRANS.bulk_amount,CUST.email,TRANS.bulk_bkng_unqId
FROM transaction TRANS
LEFT JOIN customers CUST
ON CUST.customer_id = TRANS.customer_id
WHERE TRANS.id = '"
.
$transId
.
"'"
);
if
(
!
empty
(
$result
)
&&
!
empty
(
$result
=
$result
->
row
())){
$this
->
db
->
query
(
"UPDATE orders JOIN transaction ON transaction.booking_id = orders.order_id SET orders.status = '1' WHERE transaction.bulk_bkng_unqId = '"
.
$result
->
bulk_bkng_unqId
.
"'"
);
$respArr
[
'status'
]
=
'success'
;
$respArr
[
'data'
]
=
$result
;
}
return
$respArr
;
}
public
function
getOrderDetail
(
$postData
){
$respArr
=
array
(
'status'
=>
'error'
);
if
(
empty
(
$postData
[
'ref_id'
])){
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment