# 集成站内支付

{% 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
    )
));
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://asiabill.gitbook.io/docs/ji-cheng-sdk/php-sdk/ji-cheng-zhan-nei-zhi-fu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
