def test_process_callback(): # payment callback structure example, JSON body json = read_file("fixtures/paymentCallback.json") # 'Signature' header example signature = read_file("fixtures/paymentCallback.signature") if not client.is_valid_signature(json, signature): pytest.fail("Incorrect signature") else: callback = client.from_json(json, PaymentCallback) data = callback.payment_data status = data.status if data.Status.COMPLETED == status: # ... pass elif data.Status.DECLINED == status: # ... pass else: # unknown action or unsupported status pass
def test_process_refund_callback(): # refund callback structure example, JSON body json = read_file("fixtures/refundCallback.json") # 'Signature' header example signature = read_file("fixtures/refundCallback.signature") callback_processor.process(json, signature)
def test_process_payment_callback(): # payment callback structure example, JSON body json = read_file("fixtures/paymentCallback.json") # 'Signature' header example signature = read_file("fixtures/paymentCallback.signature") callback_processor.process(json, signature)
def test_check_callback_invalid_signature(): # given json = read_file("fixtures/paymentCallback.json") expected_signature = read_file("fixtures/paymentCallback_invalid.signature") # when signature = client.calc_signature(json) # then assert expected_signature != signature
def test_process_payout_callback(): # payout callback structure example, JSON body json = read_file("fixtures/payoutCallback.json") # 'Signature' header example signature = read_file("fixtures/payoutCallback.signature") with pytest.raises(Exception) as e: callback_processor.process(json, signature) assert str(e.value) == "Please implement this method"
def test_process_callback_with_invalid_signature(): # payment callback structure example, JSON body json = read_file("fixtures/paymentCallback.json") # 'Signature' header example with invalid value signature = read_file("fixtures/paymentCallback_invalid.signature") with pytest.raises(Exception) as e: callback_processor.process(json, signature) assert str(e.value) == "Invalid callback signature"
def test_process_recurring_callback(): # recurring callback structure example, JSON body json = read_file("fixtures/recurringCallback.json") # 'Signature' header example signature = read_file("fixtures/recurringCallback.signature") with pytest.raises(Exception) as e: callback_processor.process(json, signature) assert e.type == cardpay.api_client.CallbackException assert "Can not execute handler" in str(e.value)