PurchaseRequest::getData()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 31
cts 31
cp 1
rs 9.28
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4
1
<?php
2
3
namespace Omnipay\AllPay\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
7
class PurchaseRequest extends AbstractRequest
8
{
9
    protected $apiEndpoint = 'unifiedorder';
10
11
    /**
12
     * @return array|mixed
13
     * @throws InvalidRequestException
14
     */
15 18
    public function getData()
16
    {
17 18
        $this->validate(
18 18
            'transactionReference',
19 18
            'amount',
20 18
            'paymentMethod',
21 18
            'currency',
22 18
            'returnUrl',
23 18
            'notifyUrl',
24 18
            'description',
25 18
            'items'
26
        );
27
28 18
        $data = $this->getBaseData();
29 18
        $data['transType'] = 'PURC';
30 18
        $data['orderNum'] = $this->getTransactionReference();
31 18
        $data['orderAmount'] = $this->getAmount();
32 18
        $data['paymentSchema'] = $this->getPaymentMethod();
33 18
        $data['orderCurrency'] = $this->getCurrency();
34 18
        $data['frontURL'] = $this->getReturnUrl();
35 18
        $data['backURL'] = $this->getNotifyUrl();
36 18
        $data['goodsInfo'] = $this->getDescription();
37 18
        $data['detailInfo'] = base64_encode(json_encode($this->getItems()));
38
39
        // Payment specific stuff
40
41 18
        switch ($data['paymentSchema']) {
42 18
            case 'WX':
43 18
                $data['tradeFrom'] = 'QUICK';
44 18
                break;
45 3
            case 'AP':
46 3
                $data['tradeFrom'] = 'WEB';
47 3
                break;
48 3
            case 'UP':
49 3
                $data['tradeFrom'] = 'H5';
50 3
                break;
51
        }
52
53 18
        return $data;
54
    }
55
56 12
    protected function createResponse($data)
57
    {
58 12
        return $this->response = new PurchaseResponse($this, $data);
59
    }
60
}
61