# UnionPay

## Characteristics
****
| Feature | Details |
| ------- | ------- |
| Processing currencies | USD、GBP、EUR、HKD、SGD、CNY |
| Settlement currencies | USD |
| Refunds |  ✓ |
| Partial Refunds |  ✓ |


## Payment process

1. The client from **PC** choosing to pay with unionpay will be redirected to UnionPay payment page


![企业微信截图_8909d7b5-1ede-4958-99b3-cc84d71586b2.png](https://api.apifox.cn/api/v1/projects/1296482/resources/407481/image-preview)

2. The client from **mobile** choosing to pay with unionpay will be redirected to UnionPay APP to complete the payment



![企业微信截图_83114001-0acb-4d8d-b5bf-628132280a3a.png](https://api.apifox.cn/api/v1/projects/1296482/resources/407455/image-preview)

## **Integration Method**

**Payment method enumeration values:** **`unionpay`**

**There are two integration methods for UnionPay**
1. Direct API
2. Checkout

### **Direct** **API** 

Using unionpay, customers pay by redirecting from your website or app, finish the payment, then return to your website or app where you get immediate notification on whether the payment succeeds or fails.

For direct API intergration, you can create payment intent and get url in only one step, the folllowing is the demo of creating payment intents:


#### [Create a PaymentIntent](api-42631218)
A PaymentIntent is an object that represents your intent to collect payment from your customer and tracks the lifecycle of the payment process. Create a PaymentIntent on your server and specify the amount to collect and a supported currency. If you have an existing Payment Intents integration, add unionpay to the list of payment method types.

***Request***
```
{
    "amount":1050,
    "currency":"CNY",
    "confirm":true,
    "payment_method_data" : {
        "type":"unionpay"
    },
    "return_url":"https://your.website"
}
```


***Response***
```
{
    "id": "pi_1646357082686881792",
    "object": "payment_intent",
    "created": 1681357091000,
    "currency": "CNY",
    "amount": 1050,
    "status": "requires_action",
    "livemode": true,
    "client_secret": "pi_1646357082686881792_secret_WrLaoJjPfB9FaWPfaqsxQyPx",
    "next_action": {
        "type": "unionpay_handle_redirect",
        "unionpay_handle_redirect": {
            "url": "https://api.wooshpay.com/v1/receives/paydibs/pay/1646357082686881792"
        }
    },
    "payment_method_types": [
        "unionpay"
    ],
    "confirmation_method": "automatic",
    "return_url": "https://your.website",
    "payment_method": "pm_1646357082556858368",
    "capture_method": "automatic"
}
```
### Checkout

#### [Create a seesion](api-42654181)


***Request***

```JSON
{
    "cancel_url": "www.wooshpay.com",
    "mode": "payment",
    "success_url": "https://wooshpay.com/",
    "payment_method_types": [
        "unionpay"
    ],
    "line_items": [
        {
            "price_data": {
                "currency": "CNY",
                "unit_amount": 100,
                "nickname": "apple",
                "product_data": {
                    "name": "apple"
                },
                "billing_scheme": "testscheme",
                "lookup_key": "test_lookup_key"
            },
            "quantity": 1
        }
    ]
}
```

***Response***

```JSON
{
    "id": "cs_1722490919669727232",
    "object": "checkout.session",
    "created": 1699508812000,
    "livemode": true,
    "currency": "CNY",
    "customer": "",
    "mode": "payment",
    "status": "open",
    "url": "https://checkout.wooshpay.com/pay/cs_1722490919669727232?key=cGtfbGl2ZV9OVEUzTVRZek56STJNVE14TkRVMk9UUXlNRGd4T205dmNVRmFNMGRPVTBSa2VHZzJVbWQ1V1U4MFNUSTJSREUyT1Rnd05UQXdPVFF6TVRn",
    "cancel_url": "www.wooshpay.com",
    "line_items": {
        "object": "list",
        "data": [
            {
                "id": "li_1722490919694893056",
                "object": "item",
                "currency": "CNY",
                "description": "apple",
                "price": {
                    "id": "price_1722490919703281664",
                    "object": "price",
                    "created": 1699508812000,
                    "livemode": true,
                    "active": false,
                    "currency": "CNY",
                    "nickname": "apple",
                    "product": {
                        "id": "prod_1722490919711670272",
                        "object": "product",
                        "created": 1699508812000,
                        "livemode": true,
                        "active": false,
                        "name": "apple",
                        "updated": 1699508812000
                    },
                    "type": "one_time",
                    "unit_amount": 100,
                    "billing_scheme": "per_unit",
                    "lookup_key": "test_lookup_key"
                },
                "quantity": 1,
                "amount_subtotal": 100,
                "amount_total": 100
            }
        ]
    },
    "payment_intent": "pi_1722490922173726720",
    "payment_method_types": [
        "unionpay"
    ],
    "payment_status": "unpaid",
    "success_url": "https://wooshpay.com/",
    "amount_subtotal": 100,
    "amount_total": 100,
    "billing_address_collection": "auto",
    "expires_at": 1699595212242,
    "payment_link": "",
    "client_secret": "pi_1722490922173726720_secret_fCyH13QfV89RRfXYPAVvEUOJ"
}
```

## **Next step**

You can add more features to your integration as needed

### [Create a Webhook](doc-2517709)

Listen to events on your WooshPay account so your integration can automatically trigger reactions. Create a webhook that mainly focuses on enabled_events and url.

### [Create a Refund](api-51369554)

Create a refund to repay funds to your customer. You can also perform partial refunds, but not every payment method supports them. A partial refund is when you refund only part of the original transaction amount.

