Skip to content

Commit

Permalink
Merge branch 'feature/basic-implementation' of https://github.com/PAY…
Browse files Browse the repository at this point in the history
…ONE-GmbH/PCP-ServerSDK-ruby into feature/basic-implementation
  • Loading branch information
Blackfaded committed Sep 2, 2024
2 parents bc80f76 + 59a4872 commit 3c4bbf7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
46 changes: 21 additions & 25 deletions lib/PCP-server-Ruby-SDK/transformer/apple_pay_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,33 @@
require_relative '../models/network'
require_relative '../models/payment_product320_specific_input'


module PCPServerSDK
module Transformer
class ApplePayTransformer
# Transforms an ApplePayPayment to a MobilePaymentMethodSpecificInput
# @param [PCPServerSDK::Models::ApplePayPayment] payment
# @return [PCPServerSDK::Models::MobilePaymentMethodSpecificInput]
def self.transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment)
token = payment.token || PCPServerSDK::Models::ApplePayPaymentToken.new
payment_data = token.payment_data || PCPServerSDK::Models::ApplePayPaymentData.new
header = payment_data.header || PCPServerSDK::Models::ApplePayPaymentDataHeader.new
payment_method = token.payment_method || PCPServerSDK::Models::ApplePayPaymentMethod.new
# Transforms an ApplePayPayment to a MobilePaymentMethodSpecificInput
# @param [PCPServerSDK::Models::ApplePayPayment] payment
# @return [PCPServerSDK::Models::MobilePaymentMethodSpecificInput]
def self.transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment)
token = payment.token || PCPServerSDK::Models::ApplePayPaymentToken.new
payment_data = token.payment_data || PCPServerSDK::Models::ApplePayPaymentData.new
header = payment_data.header || PCPServerSDK::Models::ApplePayPaymentDataHeader.new
payment_method = token.payment_method || PCPServerSDK::Models::ApplePayPaymentMethod.new

PCPServerSDK::Models::MobilePaymentMethodSpecificInput.new(
payment_product_id: 302,
public_key_hash: header.public_key_hash,
ephemeral_key: header.ephemeral_public_key,
payment_product302_specific_input: PCPServerSDK::Models::PaymentProduct320SpecificInput.new(
network: PCPServerSDK::Models::Network.from_string(payment_method.network.to_s),
token: PCPServerSDK::Models::ApplePaymentDataTokenInformation.new(
version: PCPServerSDK::Models::ApplePaymentTokenVersion.from_string(payment_data.version.to_s),
signature: payment_data.signature,
header: PCPServerSDK::Models::ApplePaymentDataTokenHeaderInformation.new(
transaction_id: header.transaction_id,
application_data: header.application_data
)
PCPServerSDK::Models::MobilePaymentMethodSpecificInput.new(
payment_product_id: 302,
public_key_hash: header.public_key_hash,
ephemeral_key: header.ephemeral_public_key,
payment_product302_specific_input: PCPServerSDK::Models::PaymentProduct320SpecificInput.new(
network: PCPServerSDK::Models::Network.from_string(payment_method.network.to_s),
token: PCPServerSDK::Models::ApplePaymentDataTokenInformation.new(
version: PCPServerSDK::Models::ApplePaymentTokenVersion.from_string(payment_data.version.to_s),
signature: payment_data.signature,
header: PCPServerSDK::Models::ApplePaymentDataTokenHeaderInformation.new(
transaction_id: header.transaction_id,
application_data: header.application_data
)
)
)
end
)
end

end
end
8 changes: 4 additions & 4 deletions spec/transformer/apple_pay_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative '../../lib/PCP-server-Ruby-SDK.rb'


RSpec.describe PCPServerSDK::Transformer::ApplePayTransformer do
RSpec.describe 'PCPServerSDK::Transformer::transform_apple_pay_payment_to_mobile_payment_method_specific_input' do
let(:header) do
PCPServerSDK::Models::ApplePayPaymentDataHeader.new(
public_key_hash: 'publicKeyHash123',
Expand Down Expand Up @@ -40,7 +40,7 @@
end

it 'transforms ApplePayPayment to MobilePaymentMethodSpecificInput correctly' do
result = PCPServerSDK::Transformer::ApplePayTransformer.transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment)
result = PCPServerSDK::Transformer::transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment)

expected_result = PCPServerSDK::Models::MobilePaymentMethodSpecificInput.new(
payment_product_id: 302,
Expand All @@ -63,11 +63,11 @@

it 'raises an error for unknown network' do
payment.token.payment_method.network = 'UNKNOWN'
expect { PCPServerSDK::Transformer::ApplePayTransformer.transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment) }.to raise_error(TypeError)
expect { PCPServerSDK::Transformer::transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment) }.to raise_error(TypeError)
end

it 'raises an error for unknown version' do
payment.token.payment_data.version = 'UNKNOWN'
expect { PCPServerSDK::Transformer::ApplePayTransformer.transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment) }.to raise_error(TypeError)
expect { PCPServerSDK::Transformer::transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment) }.to raise_error(TypeError)
end
end

0 comments on commit 3c4bbf7

Please sign in to comment.