Skip to content

Commit

Permalink
updated function to snakecase & exception tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 committed May 23, 2024
1 parent 72f6a90 commit 9ced9bd
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 46 deletions.
71 changes: 35 additions & 36 deletions documents/customer.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ Razorpay::Customer.fetch(customerId)
```rb
customerId = "cust_N5mywh91sXB69O"

Razorpay::Customer.fetch(customerId).addBankAccount({
"ifsc_code" : "UTIB0000194",
"account_number" :"916010082985661",
"beneficiary_name" : "Pratheek",
"beneficiary_address1" : "address 1",
"beneficiary_address2" : "address 2",
"beneficiary_address3" : "address 3",
"beneficiary_address4" : "address 4",
"beneficiary_email" : "[email protected]",
"beneficiary_mobile" : "8762489310",
"beneficiary_city" :"Bangalore",
"beneficiary_state" : "KA",
"beneficiary_country" : "IN"
Razorpay::Customer.add_bank_account(customerId,{
"ifsc_code": "UTIB0000194",
"account_number": "916010082985661",
"beneficiary_name": "Pratheek",
"beneficiary_address1": "address 1",
"beneficiary_address2": "address 2",
"beneficiary_address3": "address 3",
"beneficiary_address4": "address 4",
"beneficiary_email": "[email protected]",
"beneficiary_mobile": "8762489310",
"beneficiary_city": "Bangalore",
"beneficiary_state": "KA",
"beneficiary_country": "IN"
})
```

Expand All @@ -197,14 +197,13 @@ Razorpay::Customer.fetch(customerId).addBankAccount({
**Response:**
```json
{
"id" : "cust_1Aa00000000001",
"entity": "customer",
"name" : "Saurav Kumar",
"email" : "[email protected]",
"contact" : "+919000000000",
"gstin":"29XAbbA4369J1PA",
"notes" : [],
"created_at ": 1234567890
"id": "ba_LSZht1Cm7xFTwF",
"entity": "bank_account",
"ifsc": "ICIC0001207",
"bank_name": "ICICI Bank",
"name": "Gaurav Kumar",
"notes": [],
"account_number": "XXXXXXXXXXXXXXX0434"
}
```

Expand All @@ -217,15 +216,15 @@ customerId = "cust_N5mywh91sXB69O"

bankAccountId = "ba_N6aM8uo64IzxHu"

Razorpay::Customer.fetch(customerId).deleteBankAccount(bankAccountId)
Razorpay::Customer.delete_bank_account(customerId, bankAccountId)
```

**Parameters:**

| Name | Type | Description |
|---------------|-------------|---------------------------------------------|
| customerId* | string | Customer id of the customer whose bank account is to be deleted. |
| bankAccountId | string | The bank_id that needs to be deleted. |
| Name | Type | Description |
|---------------|-----------|-------------------------------------------------------------------|
| customerId* | string | Customer id of the customer whose bank account is to be deleted. |
| bankAccountId | string | The bank_id that needs to be deleted. |

**Response:**
```json
Expand Down Expand Up @@ -260,13 +259,13 @@ Razorpay::Customer.requestEligibilityCheck({

**Parameters:**

| Name | Type | Description |
|---------------|-------------|---------------------------------------------|
| inquiry | string | List of methods or instruments on which eligibility check is required. Possible value is `affordability`. |
| amount* | integer | The amount for which the order was created, in currency subunits. For example, for an amount of ₹295, enter `29500`. The user makes a payment for this amount against the order; hence, eligibility is checked for the amount. |
| currency* | string | A three-letter ISO code for the currency in which you want to accept the payment. Possible value is `INR`. |
| customer* | object | Customer details. [here](https://razorpay.com/docs/payments/payment-gateway/affordability/eligibility-check/#eligibility-check-api) |
| instruments | object | Payment instruments on which an eligibility check is required. [here](https://razorpay.com/docs/payments/payment-gateway/affordability/eligibility-check/#eligibility-check-api) |
| Name | Type | Description |
|-------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| inquiry | string | List of methods or instruments on which eligibility check is required. Possible value is `affordability`. |
| amount* | integer | The amount for which the order was created, in currency subunits. For example, for an amount of ₹295, enter `29500`. The user makes a payment for this amount against the order; hence, eligibility is checked for the amount. |
| currency* | string | A three-letter ISO code for the currency in which you want to accept the payment. Possible value is `INR`. |
| customer* | object | Customer details. [here](https://razorpay.com/docs/payments/payment-gateway/affordability/eligibility-check/#eligibility-check-api) |
| instruments | object | Payment instruments on which an eligibility check is required. [here](https://razorpay.com/docs/payments/payment-gateway/affordability/eligibility-check/#eligibility-check-api) |


**Response:**
Expand Down Expand Up @@ -363,9 +362,9 @@ Razorpay::Customer.fetchEligibility(eligibilityId)

**Parameters:**

| Name | Type | Description |
|---------------|-------------|---------------------------------------------|
| eligibilityId | string | The unique identifier of the eligibility request to be retrieved. |
| Name | Type | Description |
|---------------|-------------|--------------------------------------------------------------------|
| eligibilityId | string | The unique identifier of the eligibility request to be retrieved. |

**Response:**
```json
Expand Down
12 changes: 6 additions & 6 deletions lib/razorpay/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ def deleteToken(tokenId)
self.class.request.delete "#{id}/tokens/#{tokenId}"
end

def addBankAccount(options = {})
self.class.request.post "#{id}/bank_account", options
def self.add_bank_account(id, options = {})
request.post "#{id}/bank_account", options
end

def deleteBankAccount(bankAccountId)
self.class.request.delete "#{id}/bank_account/#{bankAccountId}"
def self.delete_bank_account(id, bankAccountId)
request.delete "#{id}/bank_account/#{bankAccountId}"
end

def self.requestEligibilityCheck(options = {})
def self.request_eligibility_check(options = {})
request.post "eligibility", options
end

def self.fetchEligibility(eligibilityId)
def self.fetch_eligibility(eligibilityId)
request.get "eligibility/#{eligibilityId}"
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/error_customer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "The id provided does not exist",
"source": "business",
"step": "payment_initiation",
"reason": "input_validation_failed",
"metadata": {}
}
}
10 changes: 10 additions & 0 deletions test/fixtures/error_eligibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "The eligibility id does not exist.",
"source": "NA",
"step": "NA",
"reason": "NA",
"metadata": {}
}
}
10 changes: 10 additions & 0 deletions test/fixtures/error_eligibility_check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "Amount is required.",
"source": "NA",
"step": "NA",
"reason": "NA",
"metadata": {}
}
}
60 changes: 56 additions & 4 deletions test/razorpay/test_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,37 @@ def test_customer_add_bank_account
}

stub_post(%r{customers/#{@customer_id}/bank_account$}, 'fake_bank_account', para_attr.to_json)
bankAccount = Razorpay::Customer.fetch(@customer_id).addBankAccount(para_attr.to_json)
bankAccount = Razorpay::Customer.add_bank_account(@customer_id, para_attr.to_json)
assert bankAccount.bank_name
end

def test_customer_add_bank_account_exception
para_attr = {}
stub_delete(%r{customers/#{@customer_id}/bank_account$}, 'error_customer', para_attr.to_json)
assert_raises(Razorpay::Error) do
customer = Razorpay::Customer.add_bank_account(@customer_id, para_attr.to_json)
if customer.error
raise Razorpay::Error.new, customer.error['code']
end
end
end

def test_customer_delete_bank_account
stub_delete(%r{customers/#{@customer_id}/bank_account/#{@bank_id}$}, 'success')
bankAccount = Razorpay::Customer.fetch(@customer_id).deleteBankAccount(@bank_id)
bankAccount = Razorpay::Customer.delete_bank_account(@customer_id, @bank_id)
assert bankAccount.success
end

def test_customer_delete_bank_account_exception
stub_delete(%r{customers/#{@customer_id}/bank_account/#{@bank_id}$}, 'error_customer')
assert_raises(Razorpay::Error) do
customer = Razorpay::Customer.delete_bank_account(@customer_id,@bank_id)
if customer.error
raise Razorpay::Error.new, customer.error['code']
end
end
end

def test_customer_request_eligiblity_check
para_attr = {
"inquiry": "affordability",
Expand All @@ -109,14 +130,45 @@ def test_customer_request_eligiblity_check
}
}
stub_post(%r{customers/eligibility$}, 'fake_eligiblity', para_attr.to_json)
bankAccount = Razorpay::Customer.requestEligibilityCheck(para_attr.to_json)
bankAccount = Razorpay::Customer.request_eligibility_check(para_attr.to_json)
assert bankAccount.amount
end

def test_customer_fetch_eligiblity_check_exception
para_attr = {
"inquiry": "affordability",
"currency": "INR",
"customer": {
"id": "cust_KhP5dO1dKmc0Rm",
"contact": "+918220276214",
"ip": "105.106.107.108",
"referrer": "https://merchansite.com/example/paybill",
"user_agent": "Mozilla/5.0"
}
}
stub_post(%r{customers/eligibility$}, 'error_eligibility_check', para_attr.to_json)
assert_raises(Razorpay::Error) do
customer = Razorpay::Customer.request_eligibility_check(para_attr.to_json)
if customer.error
raise Razorpay::Error.new, customer.error['code']
end
end
end

def test_customer_fetch_eligiblity
stub_get(%r{customers/eligibility/#{@eligibilityId}$}, 'fake_eligiblity')
bankAccount = Razorpay::Customer.fetchEligibility(@eligibilityId)
bankAccount = Razorpay::Customer.fetch_eligibility(@eligibilityId)
assert bankAccount.amount
end

def test_customer_fetch_eligiblity_exception
stub_get(%r{customers/eligibility/#{@eligibilityId}$}, 'error_eligibility_check')
assert_raises(Razorpay::Error) do
customer = Razorpay::Customer.fetch_eligibility(@eligibilityId)
if customer.error
raise Razorpay::Error.new, customer.error['code']
end
end
end
end
end

0 comments on commit 9ced9bd

Please sign in to comment.