/var/www/hkosl.com/littleark/webadmin/models/PayEaseDoku.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
<?php

class PayEaseDoku extends PayEase
{

    public 
$v_mid;
    protected 
$key;

    protected 
$user_payment_endpoint = array(
        
"DOKU"            => "https://pay.yizhifubj.com/customer/gb/pay_bank.jsp",
        
"DOKU_CREDITCARD" => "https://pay.yizhifubj.com/customer/gb/pay_bank.jsp",
    );

    protected 
$mer_payment_submit_utf8_sandbox_endpoint    "";
    protected 
$mer_payment_submit_utf8_production_endpoint "";
    protected 
$mer_payment_submit_utf8_endpoint;

    protected 
$mer_payment_status_utf8_sandbox_endpoint    "";
    protected 
$mer_payment_status_utf8_production_endpoint "";
    protected 
$mer_payment_status_utf8_endpoint;

    protected 
$ref_version "1.1";

    
// public function __construct($v_mid="7007", $key="test"){
    
public function __construct($v_mid null$key null)
    {
        
$this->v_mid MasterSetting::get('PAYEASE_DOKU_MID');
        
$this->key   MasterSetting::get('PAYEASE_DOKU_KEY');

        
$this->mer_payment_submit_utf8_endpoint $this->mer_payment_submit_utf8_production_endpoint;
        
$this->mer_payment_status_utf8_endpoint $this->mer_payment_status_utf8_production_endpoint;

        
$this->payment_currency "IDR";
    }

    public function 
sandbox()
    {
        
$this->v_mid                            "888";
        
$this->key                              "test";
        
$this->mer_payment_submit_utf8_endpoint $this->mer_payment_submit_utf8_sandbox_endpoint;
        
$this->mer_payment_status_utf8_endpoint $this->mer_payment_status_utf8_sandbox_endpoint;
        return 
$this;
    }

    protected function 
generateCustomizedData($args$payment_method)
    {
        
$customer            $this->invoice->customer->decrypt();
        
$data                = [];
        
$data['v_idnumber']  = _($customer->identity_id);
        
$data['v_idname']    = _($customer->first_name);
        
$data['v_idcountry'] = _(self::getIdcountry($customer->country_code)) ?: "360";
        
$data['v_idaddress'] = _($customer->addresses()->where('address_type''BILLING_ADDRESS')->first()->decrypt()->toString2());
        
$data['v_merdata1']  = _($customer->first_name);
        
$data['v_merdata2']  = _('000000000000000');
        
$data['v_merdata3']  = _($customer->tel);
        
$data['v_merdata4']  = _($customer->code);
        
$data['v_merdata5']  = get_currency_price($this->invoice->amountnull$this->payment_currency3);

        
// get invoice item
        
$supplierInvoices = [];
        foreach (
$this->invoice->invoiceItems as $invoiceItem) {
            
$proProductSku $invoiceItem->invoiceable->orderItem->proProductSku;

            
$itemunitprice number_format($invoiceItem->discounted_price $invoiceItem->invoiceable->orderItem->quantity2'.''');

            
// settle the PLATFORM, AGENT, MERCHANT payease submerchant account
            
$supplier_payease_submerchant_number $invoiceItem->supplier->getSettlementSubmerchantNumber();
            if (
$supplier_payease_submerchant_number) {
                
$supplierInvoices[$invoiceItem->supplier->payease_sub_merchant_number]['code']                        = $supplierInvoices[$invoiceItem->supplier->payease_sub_merchant_number]['code'] ?: "{$this->invoice->id}-{$invoiceItem->supplier->code}";
                
$supplierInvoices[$invoiceItem->supplier->payease_sub_merchant_number]['payease_sub_merchant_number'] = $invoiceItem->supplier->payease_sub_merchant_number;
                
$supplierInvoices[$invoiceItem->supplier->payease_sub_merchant_number]['items'][]                     = [
                    
'product_desc' => _(str_replace(['_''$'], '-'$proProductSku->getProductName/*$langcode*/))),
                    
'unitprice'    => get_currency_price($itemunitpricenull$this->payment_currency3),
                    
'quantity'     => $invoiceItem->invoiceable->orderItem->quantity,
                    
'total'        => get_currency_price($itemunitpricenull$this->payment_currency3) * $invoiceItem->invoiceable->orderItem->quantity,
                ];
            }
        }

        
/*
        子商户号,子订单编码  ,子订单金额,产品名称_产品单价_产品数量$产品名称_产品单价_产品数量||
        3       ,YYZITGQZX  ,1.50       ,%E7%94%9C%E8%AF%9D%E6%A2%85250%E5%85%8B_1.50_1||
        9       ,UMDSBAJYH  ,0.50       ,+Farinha+lactea+_0.50_1

        1,test12345,0.03,货物贸易_0.01_1$货物贸易1_0.02_1||
        2,test00002,0.02,货物贸易2_0.01_1$货物贸易3_0.01_1||
        3,test54321,0.01,货物贸易5_0.01_1
         */
        
foreach ($supplierInvoices as $payease_sub_merchant_number => $supplierInvoice) {
            
$supplierInvoiceData        = [];
            
$supplierInvoiceTotalAmount 0;
            foreach (
$supplierInvoice['items'] as $supplierInvoiceItem) {
                
$supplierInvoiceTotalAmount += $supplierInvoiceItem['total'];
                
$supplierInvoiceData[] = implode('_', [
                    
$supplierInvoiceItem['product_desc'],
                    
$supplierInvoiceItem['unitprice'],
                    
$supplierInvoiceItem['quantity'],
                ]);
            }
            
$data['v_merdata'] .= "{$payease_sub_merchant_number},{$supplierInvoice['code']},{$supplierInvoiceTotalAmount}," implode('$'$supplierInvoiceData) . "||";
        }
        
$data["v_merdata"] = substr_replace($data["v_merdata"], "", -2);

$tempSupplierInvoiceCode date('His') . 'SP';
$data["v_merdata"] = "1,{$tempSupplierInvoiceCode},{$args['v_amount']},货物贸易_{$args['v_amount']}_1";
        
// // testing data
        // $data["v_merdata"] = "1,test12345,0.03,货物贸易_0.01_1\$货物贸易1_0.02_1||2,test00002,0.02,货物贸易2_0.01_1\$货物贸易3_0.01_1||3,test54321,0.01,货物贸易5_0.01_1";
        // $data["v_amount"] = "0.06";

        
switch (strtoupper($payment_method)) {
            case 
'DOKU':
                
$data['v_pmode'] = 247;
                break;

            case 
'DOKU_CREDITCARD':
                
$data['v_pmode'] = 245;
                break;

            default:
                throw new 
Exception("Error Processing Payment Type: {$payment_method}"1);
        }
        return 
$data;
    }
}