> For the complete documentation index, see [llms.txt](https://asiabill.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://asiabill.gitbook.io/docs/ji-cheng-sdk/php-sdk/ji-cheng-zhan-nei-zhi-fu.md).

# 集成站内支付

{% content-ref url="/pages/PA7mltdpHYzwQKE6F8QT" %}
[站内支付](/docs/zhi-fu/zai-xian-zhi-fu/zhan-nei-zhi-fu.md)
{% endcontent-ref %}

### 获取sessionToken

```php
$sessiontoken = $asiabill->request('sessionToken');
```

### 前端集成JS SDK

```php
// 获取jssdk脚本
$asiabill->getJsScript();
```

1. 初始化表单 [elementInit](https://asiabill.gitbook.io/docs/ji-cheng-sdk/php-sdk/pages/PA7mltdpHYzwQKE6F8QT#2.-zhan-shi-fu-kuan-qu-yu-web)
2. 创建支付方式 [confirmPaymentMethod](https://asiabill.gitbook.io/docs/ji-cheng-sdk/php-sdk/pages/PA7mltdpHYzwQKE6F8QT#4.-chuang-jian-zhi-fu-fang-shi-web)
3. 获得customerPaymentMethodId，用户发起扣款

### 发起扣款

$data参数 [查看](https://asiabill.gitbook.io/api-explorer/api-reference/jiao-yi/confirm-charge)

```php
$data = array(
    'body' => array(
        'callbackUrl' => $callbackUrl,
        'customerId' => $customersId, 
        'customerPaymentMethodId' => $customerPaymentMethodId,
        'shipping' => array(
            'address' => array(
                'line1' => 'line1',
                'line2' => 'line2',
                'city' => 'BR',
                'country' => 'country',
                'state' => 'CE',
                'postalCode' => '666666'
            ),
            'email' => '123451234@email.com',
            'firstName' => 'firstName',
            'lastName' => 'lastName',
            'phone' => '13800138000',
        ),
        'goodsDetails' => array(
            array(  
                'goodsCount' => '1',
                'goodsPrice' => '6.00',
                'goodsTitle' => 'goods_1'
            ),
            array(  
                'goodsCount' => '1',
                'goodsPrice' => '8.00',
                'goodsTitle' => 'goods_2'
            )
        ),
        'isMobile' => $asiabill->isMobile(),
        'customerIp' => '127.0.0.1',
        'orderAmount' => '7.00',
        'orderCurrency' => 'USD',
        'orderNo' => getOrderNo(),
        'platform' => 'php_SDK',
        'remark' => '',
        'returnUrl' => $returnUrl,
        'webSite' => $_SERVER['HTTP_HOST'],
        'tokenType' => ''
    )
);
    
$confirmCharge = $asiabill->request('confirmCharge',$data);
if( $confirmCharge['code'] == '00000' ){
    /* Your business code */
}
```

### 获取客户的所有支付方式

```php
$asiabill->request('paymentMethods_list',array(
    'path' => array(
        'customerId' => $customerId,
    )
)); 
```

### 客户附加支付方式

```php
$asiabill->request('paymentMethods_attach',array(
    'path' => array(
        'customerId' => $customerId,
        'customerPaymentMethodId' => $customerPaymentMethodId
    )
));
```

### 更新客户支付方式信息

```php
$asiabill->request('paymentMethods_update',array(
    'body' => array(
        'customerPaymentMethodId' => $customerPaymentMethodId,
        'billingDetail' => array(
            'address' => array(
                'line1' => 'line1',
                'line2' => 'line2',
                'city' => 'BR',
                'country' => 'country',
                'state' => 'CE',
                'postalCode' => '666666'
            ),
            'email' => '123451234@email.com',
            'firstName' => 'firstName',
            'lastName' => 'lastName',
            'phone' => '13800138000',
        ),
        'card' => array(
            'cardNo' => '4111111111111111',
            'cardExpireMonth' => '05',
            'cardExpireYear' => '2055',
            'cardSecurityCode' => '123'
        )
    )
));
```

### 解绑支付方式

```php
$asiabill->request('paymentMethods_detach',array(
    'path' => array(
        'customerPaymentMethodId' => $customerPaymentMethodId
    )
));
```
