Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAVE-30480 Add Unit Tests for additional integration in Alipay Gem #3

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions doc/legacy_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,202 @@ notify_params = params.except(*request.path_parameters.keys)
Alipay::Notify.verify?(notify_params, options = {})
```

### QR Code 生成二维码

#### Name

```ruby
alipay.commerce.qrcode.create
```

#### Definition

```ruby
Alipay::Service.create_merchant_qr_code({PARAMS}, {OPTIONS})
```

#### Example

```ruby
create_qr_code_params = {
biz_type: "OVERSEASHOPQRCODE",
biz_data: {
address: "No.278, Road YinCheng, Shanghai, China",
country_code: "CN",
currency: "USD",
secondary_merchant_id: "xxx001",
secondary_merchant_industry: "7011",
secondary_merchant_name: "xxx Store",
store_id: "0001",
store_name: "Apple store",
trans_currency: "USD"
}
}

Alipay::Service.create_merchant_qr_code(create_qr_code_params)
# => 'https://mapi.alipay.com/gateway.do?service=alipay.commerce.qrcode.create...'
```

#### ARGUMENTS

| Key | Requirement | Description |
| --- | ----------- | ----------- |
| notify_url | optional | Alipay asyn notify url. |
| biz_type | required | Business type that is defined by Alipay, this case is “OVERSEASHOPQRCODE” |
| biz_data | required | Business data. Format:JSON |

#### BIZ_DATA ARGUMENTS (required)

| Key | Requirement | Description |
| --- | ----------- | ----------- |
| secondary_merchant_industry | required | Business category code of the secondary merchant. |
| secondary_merchant_id | required | The unique ID assigned by the partner to identify a secondary merchant. |
| secondary_merchant_name | required | Registration legal name of the secondary merchant, shown in the Alipay Wallet and the reconciliation file to identify a secondary merchant. |
| store_id | required | The unique ID that is assigned by the partner to identify a store of a merchant. |
| store_name | required | The name of the store. |
| trans_currency | required | The pricing currency |
| currency | required | The currency to settle with the merchant. The default value is CNY. If the pricing currency is not CNY, then the settlement currency must be either CNY or the pricing currency. |
| country_code | required | The country code that consists of two letters (alpha-2 code) |
| address | required | The address of the store where the code is created. |

This is not a complete list of arguments, please read official document: https://global.alipay.com/docs/ac/global/qrcode_create#biz_data

### QR Code 修改二维码

#### Name

```ruby
alipay.commerce.qrcode.modify
```

#### Definition

```ruby
Alipay::Service.update_merchant_qr_code({PARAMS}, {OPTIONS})
```

#### Example

```ruby
update_qr_code_params = {
biz_type: "OVERSEASHOPQRCODE",
qrcode: "https://qr.alipay.com/baxxxxx",
biz_data: {
address: "No.278, Road YinCheng, Shanghai, China",
country_code: "CN",
currency: "USD",
secondary_merchant_id: "xxx001",
secondary_merchant_industry: "7011",
secondary_merchant_name: "xxx Store",
store_id: "0001",
store_name: "Apple store",
trans_currency: "USD"
}
}

Alipay::Service.update_merchant_qr_code(update_qr_code_params)
# => 'https://mapi.alipay.com/gateway.do?service=alipay.commerce.qrcode.modify...'
```

#### ARGUMENTS

| Key | Requirement | Description |
| --- | ----------- | ----------- |
| notify_url | optional | Alipay asyn notify url. |
| biz_type | required | Business type that is defined by Alipay, this case is “OVERSEASHOPQRCODE” |
| biz_data | required | Business data. Format:JSON |
| qrcode | required | The returned QR code value after the code is generated successfully. |

#### BIZ_DATA ARGUMENTS (required)

| Key | Requirement | Description |
| --- | ----------- | ----------- |
| secondary_merchant_industry | required | Business category code of the secondary merchant. |
| secondary_merchant_id | required | The unique ID assigned by the partner to identify a secondary merchant. |
| secondary_merchant_name | required | Registration legal name of the secondary merchant, shown in the Alipay Wallet and the reconciliation file to identify a secondary merchant. |
| store_id | required | The unique ID that is assigned by the partner to identify a store of a merchant. |
| store_name | required | The name of the store. |
| trans_currency | required | The pricing currency |
| currency | required | The currency to settle with the merchant. The default value is CNY. If the pricing currency is not CNY, then the settlement currency must be either CNY or the pricing currency. |
| country_code | required | The country code that consists of two letters (alpha-2 code) |
| address | required | The address of the store where the code is created. |

This is not a complete list of arguments, please read official document: https://global.alipay.com/docs/ac/global/qrcode_modify#Qb0Hc

### 境外线下交易查询接口

#### Name

```ruby
alipay.acquire.overseas.query
```

#### Definition

```ruby
Alipay::Service.acquirer_overseas_query({PARAMS}, {OPTIONS})
```

#### Example

```ruby
acquirer_overseas_query_params = {
partner_trans_id: "2010121000000002"
}

Alipay::Service.acquirer_overseas_query(acquirer_overseas_query_params)
# => 'https://mapi.alipay.com/gateway.do?service=alipay.acquire.overseas.query...'
```

#### ARGUMENTS

| Key | Requirement | Description |
| --- | ----------- | ----------- |
| partner_trans_id | required | The original partner transaction ID given in the payment request |
| alipay_trans_id | optional | The transaction ID assigned by Alipay for the partner's payment request, which follows a mapping relation with the partner field plus the partner_trans_id field. When both of the fields are specified, alipay_trans_id will be verified first. |

Document: https://global.alipay.com/docs/ac/global/overseas_query

### 境外线下单笔退款接口

#### Name

```ruby
alipay.acquire.overseas.spot.refund
```

#### Definition

```ruby
Alipay::Service.acquirer_overseas_spot_refund_url({PARAMS}, {OPTIONS})
```

#### Example

```ruby
acquirer_overseas_spot_refund_params = {
partner_trans_id: "2010121000000002",
partner_refund_id: "301012133000002",
currency: "USD",
refund_amount: "0.01"
}

Alipay::Service.acquirer_overseas_spot_refund_url(acquirer_overseas_spot_refund_params)
# => 'https://mapi.alipay.com/gateway.do?service=alipay.acquire.overseas.spot.refund...'
```

#### ARGUMENTS

| Key | Requirement | Description |
| --- | ----------- | ----------- |
| partner_trans_id | required | The original partner transaction ID given in the payment request |
| partner_refund_id | required | The refund order ID in the partner system. The value of partner_refund_id cannot be the same as that of partner_trans_id. The partner_refund_id field plus the partner field identifies a refund transaction. |
| currency | required | The currency of the refund amount. |
| refund_amount | required | Refund amount, which must be less than or equal to the original transaction amount or the left transaction amount if ever refunded. |
| is_sync | optional | Indicates that the refund request is processed synchronously or asynchronously with a value of Y or N. The default value is N, which means an asynchronous notification from Alipay is returned to the merchant if the merchant has set the value of the notify_url field when sending the refund request. If the value is set as Y, it means only a synchronous response is returned to the merchant. |

This is not a complete list of arguments, please read official document: https://global.alipay.com/docs/ac/global/spot_refund#92fa0c95

## Mobile::Service

### 移动支付接口
Expand Down
7 changes: 2 additions & 5 deletions lib/alipay/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,14 @@ def self.create_forex_trade_wap_url(params, options = {})
request_uri(params, options).to_s
end

# Alipay Commerce
# alipay doc: https://global.alipay.com/service/merchant_QR_Code/15

CREATE_MERCHANT_QR_CODE_REQUIRED_PARAMS = %w( biz_type biz_data )
CREATE_MERCHANT_QR_CODE_REQUIRED_BIZ_DATA_PARAMS = %w( secondary_merchant_industry secondary_merchant_id secondary_merchant_name trans_currency currency )
def self.create_merchant_qr_code(params, options = {})
params = Utils.stringify_keys(params)
check_required_params(params, CREATE_MERCHANT_QR_CODE_REQUIRED_PARAMS)
biz_data = nil

if params['biz_data'].present?
if params['biz_data']
Comment on lines -222 to +219
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.present? is only work in rails, so to make this gem working fine even with pure ruby, just check using the params will do

params['biz_data'] = Utils.stringify_keys(params['biz_data'])
check_required_params(params['biz_data'], CREATE_MERCHANT_QR_CODE_REQUIRED_BIZ_DATA_PARAMS)

Expand Down Expand Up @@ -248,7 +245,7 @@ def self.update_merchant_qr_code(params, options = {})
check_required_params(params, UPDATE_MERCHANT_QR_CODE_REQUIRED_PARAMS)
biz_data = nil

if params['biz_data'].present?
if params['biz_data']
params['biz_data'] = Utils.stringify_keys(params['biz_data'])

data = params.delete('biz_data')
Expand Down
65 changes: 65 additions & 0 deletions test/alipay/service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,69 @@ def test_batch_trans_notify_url

assert_equal 'https://mapi.alipay.com/gateway.do?service=batch_trans_notify&_input_charset=utf-8&partner=1000000000000000&pay_date=20080107&notify_url=https%3A%2F%2Fexample.com%2Forders%2F20150401000-0001%2Fnotify&account_name=%E6%AF%9B%E6%AF%9B&detail_data=0315006%5Etestture0002%40126.com%5E%E5%B8%B8%E7%82%9C%E4%B9%B0%E5%AE%B6%5E1000.00%5Ehello&batch_no=20080107001&batch_num=1&batch_fee=1000.0&email=biz_932%40alitest.com&sign_type=MD5&sign=59c611607daafd1337e96b22404bd521', Alipay::Service.batch_trans_notify_url(options)
end

def test_create_merchant_qr_code
params = {
biz_type: "OVERSEASHOPQRCODE",
biz_data: {
address: "No.278, Road YinCheng, Shanghai, China",
country_code: "CN",
currency: "USD",
secondary_merchant_id: "xxx001",
secondary_merchant_industry: "7011",
secondary_merchant_name: "xxx Store",
store_id: "0001",
store_name: "Apple store",
trans_currency: "USD"
}
}

current_time = Time.new(2023, 12, 12, 1, 1, 1)
Time.stub :now, current_time do
assert_equal 'https://mapi.alipay.com/gateway.do?service=alipay.commerce.qrcode.create&_input_charset=utf-8&partner=1000000000000000&timestamp=2023-12-11+17%3A01%3A01&biz_data=%7B%22address%22%3A+%22No.278%2C+Road+YinCheng%2C+Shanghai%2C+China%22%2C%22country_code%22%3A+%22CN%22%2C%22currency%22%3A+%22USD%22%2C%22secondary_merchant_id%22%3A+%22xxx001%22%2C%22secondary_merchant_industry%22%3A+%227011%22%2C%22secondary_merchant_name%22%3A+%22xxx+Store%22%2C%22store_id%22%3A+%220001%22%2C%22store_name%22%3A+%22Apple+store%22%2C%22trans_currency%22%3A+%22USD%22%7D&biz_type=OVERSEASHOPQRCODE&sign_type=MD5&sign=fbfcc8c9316cc209c385eefcbceb2105', Alipay::Service.create_merchant_qr_code(params)
end
end

def test_update_merchant_qr_code
params = {
biz_type: "OVERSEASHOPQRCODE",
qr_code: "https://qr.alipay.com/baxxxxx",
biz_data: {
address: "No.278, Road YinCheng, Shanghai, China",
country_code: "CN",
currency: "USD",
secondary_merchant_id: "xxx001",
secondary_merchant_industry: "7011",
secondary_merchant_name: "xxx Store",
store_id: "0001",
store_name: "Apple store",
trans_currency: "USD"
}
}

current_time = Time.new(2023, 12, 12, 1, 1, 1)
Time.stub :now, current_time do
assert_equal 'https://mapi.alipay.com/gateway.do?service=alipay.commerce.qrcode.modify&_input_charset=utf-8&partner=1000000000000000&timestamp=2023-12-11+17%3A01%3A01&biz_data=%7B%22address%22%3A+%22No.278%2C+Road+YinCheng%2C+Shanghai%2C+China%22%2C%22country_code%22%3A+%22CN%22%2C%22currency%22%3A+%22USD%22%2C%22secondary_merchant_id%22%3A+%22xxx001%22%2C%22secondary_merchant_industry%22%3A+%227011%22%2C%22secondary_merchant_name%22%3A+%22xxx+Store%22%2C%22store_id%22%3A+%220001%22%2C%22store_name%22%3A+%22Apple+store%22%2C%22trans_currency%22%3A+%22USD%22%7D&biz_type=OVERSEASHOPQRCODE&qr_code=https%3A%2F%2Fqr.alipay.com%2Fbaxxxxx&sign_type=MD5&sign=5a72863d023163147f2909e74b741e52', Alipay::Service.update_merchant_qr_code(params)
end
end

def test_acquirer_overseas_query
params = {
partner_trans_id: "2010121000000002"
}

assert_equal 'https://mapi.alipay.com/gateway.do?service=alipay.acquire.overseas.query&_input_charset=utf-8&partner=1000000000000000&partner_trans_id=2010121000000002&sign_type=MD5&sign=2a7f598bbb13d02f7de819ae689f80ba', Alipay::Service.acquirer_overseas_query(params)
end

def test_acquirer_overseas_spot_refund_url
params = {
partner_trans_id: "2010121000000002",
partner_refund_id: "301012133000002",
currency: "USD",
refund_amount: "0.01",
is_sync: "Y"
}

assert_equal 'https://mapi.alipay.com/gateway.do?service=alipay.acquire.overseas.spot.refund&_input_charset=utf-8&partner=1000000000000000&partner_trans_id=2010121000000002&partner_refund_id=301012133000002&currency=USD&refund_amount=0.01&is_sync=Y&sign_type=MD5&sign=397685a0c6b2d71d0d1f374ddba331a0', Alipay::Service.acquirer_overseas_spot_refund_url(params)
end
end