/var/www/hkosl.com/littleark/webadmin/models/AbstractPaymentGateway.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
<?php
/**
 * @author Garrick Lam
 */

abstract class AbstractPaymentGateway
{
    
/**
     * switch the sandbox settings for testing
     * @return AbstractPaymentGateway self object for method chaining
     */
    
abstract public function sandbox();

    
/**
     * generated parameter for calling or redirect user to the payment gateway
     * @param  string $payment_method payment method
     * @return array               prepared parameters
     */
    
abstract public function paymentParam($payment_method);

    
/**
     * Verify the payment is completed by hash or post back
     * @param  array $data      received data
     * @param  array  &$messages errors generated in verification
     * @return boolean            success or fail
     */
    
abstract public function paymentVerify($data, &$messages = array());

    
/**
     * receive all payment notification or webhook
     * @param  array $request received data
     * @return boolean       success or fail
     */
    
abstract public function processNotification($request);

    
/**
     * Add an invoice to be paid
     */
    
public function setInvoice(Invoice $invoice)
    {
        
$this->invoice $invoice;
    }

    
/**
     * post a message to the api
     * @param  String $endpoint URL of the API
     * @param  Array $param    parameters
     * @return String           Response
     */
    
protected static function _excute($endpoint$param)
    {
        
$ch curl_init();
        
curl_setopt($chCURLOPT_URL$endpoint);
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($chCURLOPT_POSTtrue);
        
curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($param));
        
$output curl_exec($ch);
        
curl_close($ch);

        return 
$output;
    }
}