def test_payments_client_full_card_auth_request(self): payment = self.auth_card() self.assertEqual(payment.http_response.status, 200) # test payment self.assertTrue(Utils.is_id(payment.id, short_id=True)) self.assertTrue(payment.approved) self.assertEqual(payment.value, 100) self.assertEqual(payment.currency, 'USD') self.assertEqual(payment.track_id, 'ORDER-001-002') # test card self.assertTrue(Utils.is_id(payment.card.id), 'card') self.assertEqual(int(payment.card.expiryMonth), 6) self.assertEqual(int(payment.card.expiryYear), 2025) self.assertEqual(payment.card.last4, '4242') self.assertEqual(payment.card.name, 'Joe Smith') # test customer self.assertTrue(Utils.is_id(payment.customer.id, 'cust')) self.assertEqual(payment.customer.email, '*****@*****.**') # test other content from the http body body = payment.http_response.body self.assertEqual(body['card']['billingDetails']['city'], 'London') self.assertEqual( body['transactionIndicator'], sdk.PaymentType.Recurring.value) # pylint: disable = no-member self.assertEqual(body['udf1'], 'udf1') # below is also a test of snake >> camel casing. self.assertEqual(body['customerIp'], '8.8.8.8') self.assertEqual(body['products'][0]['price'], 2000)
def test_is_id(self): self.assertEqual(Utils.is_id(self.CARD_ID, 'card', False), True, 'Card Id unexpectedly invalid') self.assertEqual(Utils.is_id(self.CUSTOMER_ID, 'cust', False), True, 'Customer Id unexpectedly invalid') self.assertEqual(Utils.is_id(self.PAYMENT_ID, 'charge_test', True), True, 'Charge Id unexpectedly invalid') self.assertEqual(Utils.is_id(self.CARD_ID, '...', False), False, 'Card Id unexpectedly valid') self.assertEqual(Utils.is_id(self.CARD_ID, 'card', True), False, 'Card Id unexpectedly valid')
def test_payments_client_void_request(self): payment = self.auth_card() # void the previous auth request response = self.client.void(payment.id, track_id='ORDER-001-002-VOID') self.assertEqual(response.http_response.status, 200) # test payment self.assertTrue(Utils.is_id(response.id, short_id=True)) self.assertTrue(Utils.is_id(response.original_id, short_id=True)) self.assertEqual(response.track_id, 'ORDER-001-002-VOID') self.assertTrue(response.approved)
def test_payments_client_capture_partial_amount_request(self): payment = self.auth_card(value=150) # capture the previous auth request response = self.client.capture(payment.id, value=100, track_id='ORDER-001-002-CAPTURE') self.assertEqual(response.http_response.status, 200) # test payment self.assertTrue(Utils.is_id(response.id, short_id=True)) self.assertTrue(Utils.is_id(response.original_id, short_id=True)) self.assertEqual(response.track_id, 'ORDER-001-002-CAPTURE') self.assertEqual(response.value, 100) self.assertTrue(response.approved)
def test_payments_client_refund_full_amount_request(self): payment = self.auth_card(value=150) # capture the previous auth request capture = self.client.capture(payment.id, track_id='ORDER-001-002-CAPTURE') self.assertEqual(payment.id, capture.original_id) # refund the capture response = self.client.refund(capture.id, track_id='ORDER-001-002-REFUND') self.assertEqual(response.http_response.status, 200) # test payment self.assertTrue(Utils.is_id(response.id, short_id=True)) self.assertTrue(Utils.is_id(response.original_id, short_id=True)) self.assertEqual(capture.id, response.original_id) self.assertEqual(response.track_id, 'ORDER-001-002-REFUND') self.assertEqual(response.value, 150) self.assertTrue(response.approved)
def request(self, card=None, token=None, value=0, currency=sdk.default_currency, payment_type=sdk.default_payment_type, customer=None, track_id=None, auto_capture=sdk.default_auto_capture, auto_capture_delay=sdk.default_auto_capture_delay, **kwargs): payment_source = card or token # card can be a dictionary and need the JSON case converted, if needed, before being validated if isinstance(card, dict): card = self._convert_json_case(card) # change payment source to a masked PAN payment_source = Utils.mask_pan(card['number']) self._log_info('Auth {} - {}{} - {}'.format( payment_source, value, currency, track_id if track_id else '<no track id>')) Utils.validate_payment_source(card=card, token=token) Utils.validate_transaction(value=value, currency=currency, payment_type=payment_type) Utils.validate_customer(customer=customer) request = { 'value': value, 'currency': currency if not isinstance(currency, sdk.Currency) else currency.value, 'trackId': track_id, 'transactionIndicator': payment_type if not isinstance(payment_type, sdk.PaymentType) else payment_type.value, 'autoCapture': 'Y' if auto_capture else 'N', 'autoCapTime': auto_capture_delay } if card: if isinstance(card, dict): request['card'] = card else: request['cardId'] = card else: request['cardToken'] = token if Utils.is_id(customer): request['customerId'] = customer else: request['email'] = customer # add remaining properties request.update(kwargs) return PaymentProcessed( self._send_http_request( 'charges/card' if card is not None else 'charges/token', HttpMethod.POST, request))