|
| 1 | +headers = {} |
| 2 | +headers['x-amz-pay-idempotency-key'] = SecureRandom.uuid.to_s.gsub(/-/, '') |
| 3 | + |
| 4 | +config = Config.get_config |
| 5 | + |
| 6 | +client = AmazonPay::AmazonInStoreClient.new(config) |
| 7 | +charge_permission_id = '' # Enter Charge Permission ID |
| 8 | +charge_id = '' |
| 9 | + |
| 10 | +merchant_scan_payload = { |
| 11 | + scanData: 'UKhrmatMeKdlfY6b', |
| 12 | + scanReferenceId: SecureRandom.uuid.to_s.gsub(/-/, ''), |
| 13 | + merchantCOE: config[:country_code], |
| 14 | + ledgerCurrency: config[:currency_code], |
| 15 | + storeLocation: { |
| 16 | + countryCode: config[:country_code] |
| 17 | + }, |
| 18 | + metadata: { |
| 19 | + merchantNote: 'Software Purchase', |
| 20 | + customInformation: 'in-store Software Purchase', |
| 21 | + communicationContext: { |
| 22 | + merchantStoreName: 'TESTSTORE', |
| 23 | + merchantOrderId: '789123' |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +merchant_scan_expected_response = { |
| 29 | + chargePermissionId: '' |
| 30 | +} |
| 31 | + |
| 32 | +charge_expected_response = { |
| 33 | + chargeId: '', |
| 34 | + chargeStatus: { |
| 35 | + state: 'Completed' |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +refund_expected_response = { |
| 40 | + refundId: '', |
| 41 | + refundStatus: { |
| 42 | + state: 'Pending' |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +RSpec.describe 'InStore Client Test Cases' do |
| 47 | + it 'Validating Merchant Scan API' do |
| 48 | + result = client.merchant_scan(payload: merchant_scan_payload, headers: headers) |
| 49 | + charge_permission_id = result[:chargePermissionId] |
| 50 | + result = result.transform_keys(&:to_sym) |
| 51 | + expect(result.keys).to eq(merchant_scan_expected_response.keys) |
| 52 | + end |
| 53 | + |
| 54 | + it 'Validating Charge API' do |
| 55 | + charge_payload = { |
| 56 | + chargePermissionId: charge_permission_id, |
| 57 | + chargeReferenceId: SecureRandom.uuid.to_s.gsub(/-/, ''), |
| 58 | + chargeTotal: { |
| 59 | + currencyCode: config[:currency_code], |
| 60 | + amount: 2 |
| 61 | + }, |
| 62 | + softDescriptor: 'amzn-store' |
| 63 | + } |
| 64 | + result = client.charge(payload: charge_payload) |
| 65 | + charge_id = result[:chargeId] |
| 66 | + result = result.transform_keys(&:to_sym) |
| 67 | + expect(result.keys).to eq(charge_expected_response.keys) |
| 68 | + end |
| 69 | + |
| 70 | + it 'Validating Refund API' do |
| 71 | + refund_payload = { |
| 72 | + chargeId: charge_id, |
| 73 | + refundReferenceId: SecureRandom.uuid.to_s.gsub(/-/, ''), |
| 74 | + refundTotal: { |
| 75 | + currencyCode: config[:currency_code], |
| 76 | + amount: 2 |
| 77 | + }, |
| 78 | + softDescriptor: 'amzn-store' |
| 79 | + } |
| 80 | + result = client.refund(payload: refund_payload) |
| 81 | + |
| 82 | + result = result.transform_keys(&:to_sym) |
| 83 | + expect(result.keys).to eq(refund_expected_response.keys) |
| 84 | + end |
| 85 | +end |
0 commit comments