Skip to content

Commit

Permalink
v6.0.0
Browse files Browse the repository at this point in the history
Co-Authored-By: Patryk Smolarz <[email protected]>
  • Loading branch information
p-zielinski and patryksmolarz committed Sep 4, 2024
1 parent a77b09f commit 70defbc
Show file tree
Hide file tree
Showing 2,461 changed files with 168,123 additions and 103,064 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- **2024-05-08** - `5.0.1` - Added support for [Create validation rule assignment](https://docs.voucherify.io/reference/create-validation-rule-assignment)
- **2024-03-11** - `5.0.0` - The new version of the SKD includes coverage for all the most commonly used Voucherify endpoints and supports typed models.
- **2022-01-18** - `4.1.0` - Async Actions support.
- **2021-06-14** - `4.0.0` - Bumped required ruby version, bumped dependencies, added `Consents` API support, remove deprecated `URI.escape`.
- **2020-03-09** - `3.0.0` - Bumped required ruby version, bumped dependencies, added `list` method in Customers module.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
COPY . .

RUN gem build VoucherifySdk.gemspec
RUN gem install voucherify-5.0.1.gem
RUN gem install voucherify-6.0.0.gem
RUN gem install dotenv
RUN gem install rspec

Expand Down
1,128 changes: 306 additions & 822 deletions ENDPOINTS-COVERAGE.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ gem build VoucherifySdk.gemspec
Then either install the gem locally:

```shell
gem install ./VoucherifySdk-5.0.1.gem
gem install ./VoucherifySdk-6.0.0.gem
```

(for development, run `gem install --dev ./VoucherifySdk-5.0.1.gem` to install the development dependencies)
(for development, run `gem install --dev ./VoucherifySdk-6.0.0.gem` to install the development dependencies)

Add this to the Gemfile:

```shell
gem 'VoucherifySdk', '~> 5.0.1'
gem 'VoucherifySdk', '~> 6.0.0'
```

Then install dependencies with bundler
Expand Down
916 changes: 611 additions & 305 deletions README.md

Large diffs are not rendered by default.

34 changes: 27 additions & 7 deletions __tests__/lib/campaigns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create_validation_rule_applicable_to(validation_rules_api_instance, product_
created_validation_rule = validation_rules_api_instance.create_validation_rules({
validation_rules_create_request_body: VoucherifySdk::ValidationRulesCreateRequestBody.new({
name: generate_random_string(),
applicable_to: VoucherifySdk::ValidationRuleBaseApplicableTo.new({
applicable_to: VoucherifySdk::ValidationRulesCreateRequestBodyApplicableTo.new({
included: [VoucherifySdk::ApplicableTo.new({
object: "product",
id: product_id
Expand Down Expand Up @@ -50,20 +50,21 @@ def create_validation_rule_more_than(validation_rules_api_instance, product_id)
def create_discount_campaign(campaigns_api_instance, validation_rule_id)
begin
campaign = campaigns_api_instance.create_campaign({
campaigns_create_request_body: VoucherifySdk::CampaignsCreateDiscountCouponsCampaign.new({
campaigns_create_request_body: VoucherifySdk::CampaignsCreateRequestBody.new({
campaign_type: "DISCOUNT_COUPONS",
name: generate_random_string(),
type: "AUTO_UPDATE",
voucher: VoucherifySdk::DiscountCouponsCampaignVoucher.new({
discount: VoucherifySdk::DiscountAmount.new({
type: "AMOUNT",
voucher: VoucherifySdk::CampaignsCreateRequestBodyVoucher.new({
type: 'DISCOUNT_VOUCHER',
discount: VoucherifySdk::Discount.new({
type: 'AMOUNT',
amount_off: 1000
})
}),
validation_rules: [validation_rule_id]
})
})

return campaign
rescue VoucherifySdk::ApiError => e
return nil
Expand Down Expand Up @@ -111,6 +112,7 @@ def create_loyalty_campaign(campaigns_api_instance)
}
}
})
return campaign
end
end

Expand All @@ -124,5 +126,23 @@ def delete_campaign(campaigns_api_instance, campaign_id)
end
end


def add_vouchers_to_campaign(campaigns_api_instance, campaign_id, voucher_count)
begin
vouchers = []

voucher_count.times do
voucher = campaigns_api_instance.add_vouchers_to_campaign(
campaign_id,
{
vouchers_count: 1
}
)
vouchers << voucher.code
end

return vouchers
rescue VoucherifySdk::ApiError => e
return nil
end
end

13 changes: 9 additions & 4 deletions __tests__/lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ def self.events_api_instance
return VoucherifySdk::EventsApi.new()
end

def generate_random_string(length=10)
chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
random_string = Array.new(length) { chars.sample }.join
return random_string
def self.order_api_instance
return VoucherifySdk::OrdersApi.new()
end

def self.loyalties_api_instance
return VoucherifySdk::LoyaltiesApi.new()
end

def self.vouchers_api_instance
return VoucherifySdk::VouchersApi.new()
end
end

2 changes: 1 addition & 1 deletion __tests__/lib/customers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create_customer(customers_api_instance)
customers_create_request_body: VoucherifySdk::CustomersCreateRequestBody.new({
source_id: generate_random_string(),
name: "John Doe",
address: VoucherifySdk::CustomerBaseAddress.new({
address: VoucherifySdk::CustomerAddress.new({
country: "US",
city: "New York",
line_1: "5th Avenue",
Expand Down
32 changes: 32 additions & 0 deletions __tests__/lib/loyalties.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative 'utils.rb'
require 'VoucherifySdk'

def update_loyalty_card_balance(loyalties_api_instance, memberId)
begin
updated_loyalty_member_card = loyalties_api_instance.update_loyalty_card_balance(memberId, {
loyalties_members_balance_update_request_body: VoucherifySdk::LoyaltiesMembersBalanceUpdateRequestBody.new({
points: 2000
})
})

return updated_loyalty_member_card

rescue VoucherifySdk::ApiError => e
retun nil
end
end

def list_loyalty_card_transactions(loyalties_api_instance, memberId)
begin
transactions = loyalties_api_instance.list_loyalty_card_transactions(memberId,
{
limit: 10,
page: 1
})

return transactions

rescue VoucherifySdk::ApiError => e
return nil
end
end
67 changes: 67 additions & 0 deletions __tests__/lib/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require_relative 'utils.rb'
require 'VoucherifySdk'

def create_order(order_api_instance)
begin
created_order = order_api_instance.create_order({
orders_create_request_body: VoucherifySdk::OrdersCreateRequestBody.new({
amount: 10000,
status: 'CREATED',
items: [
{
product_id: 'test_order_item1',
quantity: 1
},
{
product_id: 'test_order_item2',
quantity: 1
}
]
})
})

return created_order

rescue VoucherifySDk::ApiError => e
return nil
end
end

def get_order(order_api_instance, orderId)
begin
order = order_api_instance.get_order(orderId)

return order

rescue VoucherifySdk::ApiError => e
return nil
end
end

def update_order(order_api_instance, orderId)
updated_order = order_api_instance.update_order(orderId, {
orders_update_request_body: VoucherifySdk::OrdersUpdateRequestBody.new({
amount: 30000,
status: 'PAID'
})
})

return updated_order

rescue VoucherifySdk::ApiError => e
return nil
end

def list_orders(order_api_instance)
begin
orders = order_api_instance.list_orders({
limit: 10,
page: 1
})

return orders

rescue VoucherifySdk::ApiError => e
return nil
end
end
18 changes: 12 additions & 6 deletions __tests__/lib/stackables.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def create_request_body_redeemable(voucher_id)
begin
validations_validate_request_body_redeemables = [
VoucherifySdk::RedeemVoucher.new({
VoucherifySdk::RedemptionEntryVoucher.new({
object: "voucher", id: voucher_id
})
]
Expand All @@ -10,11 +10,14 @@ def create_request_body_redeemable(voucher_id)
end


def validate_stacked_discounts(validations_api_instance, voucher_id, product_id, customer, amount)
def validate_stacked_discounts(validations_api_instance, voucher_ids, product_id, customer, amount)
begin
voucher_ids = [voucher_ids] unless voucher_ids.is_a?(Array)
redeemables = voucher_ids.map { |voucher_id| create_request_body_redeemable(voucher_id) }.flatten

result = validations_api_instance.validate_stacked_discounts({
validations_validate_request_body: VoucherifySdk::ValidationsValidateRequestBody.new({
redeemables: create_request_body_redeemable(voucher_id),
redeemables: redeemables,
order: {
items: [{
related_object: "product",
Expand All @@ -39,19 +42,22 @@ def validate_stacked_discounts(validations_api_instance, voucher_id, product_id,
})
return result;
rescue VoucherifySdk::ApiError => e
puts(e)
return nil;
end
end

def redeem_stacked_discounts(redemptions_api_instance, voucher_id)
def redeem_stacked_discounts(redemptions_api_instance, voucher_ids)
begin
voucher_ids = [voucher_ids] unless voucher_ids.is_a?(Array)
redeemables = voucher_ids.map { |voucher_id| create_request_body_redeemable(voucher_id) }.flatten

result = redemptions_api_instance.redeem_stacked_discounts({
redemptions_redeem_request_body: VoucherifySdk::RedemptionsRedeemRequestBody.new({
redeemables: create_request_body_redeemable(voucher_id),
redeemables: redeemables,
order: VoucherifySdk::Order.new(amount: 20000)
})
})

return result;
rescue VoucherifySdk::ApiError => e
return nil;
Expand Down
4 changes: 4 additions & 0 deletions __tests__/lib/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ def generate_random_string(length=10)
random_string = Array.new(length) { chars.sample }.join
return random_string
end

def generate_random_voucher_codes(base_code, count, length=6)
(1..count).map { "#{base_code}-#{generate_random_string(length)}" }
end
9 changes: 9 additions & 0 deletions __tests__/lib/voucherify_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize
@product_ids = []
@sku = nil
@validation_rule = nil
@order = nil
end

def set_discount_campaign(discount_campaign)
Expand Down Expand Up @@ -101,4 +102,12 @@ def get_validation_rule
def set_loyalty_card(loyalty_card)
@loyalty_card = loyalty_card
end

def set_order(order)
@order = order
end

def get_order
@order
end
end
Loading

0 comments on commit 70defbc

Please sign in to comment.