Пример #1
0
    def update_subscription_payment(self, subscription_id):

        self.transaction_type = apicontractsv1.ARBSubscriptionType()
        self.transaction_type.payment = self.create_authorize_payment()

        self.transaction = apicontractsv1.ARBUpdateSubscriptionRequest()
        self.transaction.merchantAuthentication = self.merchant_auth
        self.transaction.subscriptionId = subscriptionId
        self.transaction.subscription = self.transaction_type

        self.controller = ARBUpdateSubscriptionController(self.transaction)
        self.controller.execute()

        response = self.controller.getresponse()

        if (response.messages.resultCode == "Ok"):
            print("SUCCESS")
            print("Message Code : %s" %
                  response.messages.message[0]['code'].text)
            print("Message text : %s" %
                  response.messages.message[0]['text'].text)
        else:
            print("ERROR")
            print("Message Code : %s" %
                  response.messages.message[0]['code'].text)
            print("Message text : %s" %
                  response.messages.message[0]['text'].text)

        return response
Пример #2
0
    def subscription_update_payment(self, receipt):
        """
        Updates the credit card information for the subscriptions in authorize.net 
        and updates the payment record associated with the receipt.
        """
        self.payment = Payment.objects.get(success=True,
                                           transaction=receipt.transaction,
                                           invoice=receipt.order_item.invoice)

        self.transaction_type = apicontractsv1.ARBSubscriptionType()
        self.transaction_type.payment = self.create_authorize_payment()

        self.transaction = apicontractsv1.ARBUpdateSubscriptionRequest()
        self.transaction.merchantAuthentication = self.merchant_auth
        self.transaction.subscriptionId = str(receipt.transaction)
        self.transaction.subscription = self.transaction_type

        self.controller = ARBUpdateSubscriptionController(self.transaction)
        self.set_controller_api_endpoint()
        self.controller.execute()

        response = self.controller.getresponse()

        self.check_subscription_response(response)

        receipt.meta[f"payment-update-{timezone.now():%Y-%m-%d %H:%M}"] = {
            'raw': str({
                **self.transaction_message,
                **response
            })
        }
        receipt.save()

        subscription_info = self.subscription_info(receipt.transaction)

        account_number = getattr(
            subscription_info['subscription']['profile']['paymentProfile']
            ['payment']['creditCard'], 'cardNumber', None)
        if account_number:
            self.payment.result['account_number'] = account_number.text

        account_type = getattr(
            subscription_info['subscription']['profile']['paymentProfile']
            ['payment']['creditCard'], 'accountType', None)
        if account_type:
            self.payment.result['account_type'] = account_type.text

        self.payment.save()
def update_subscription(subscriptionId):
	merchantAuth = apicontractsv1.merchantAuthenticationType()
	merchantAuth.name = constants.apiLoginId
	merchantAuth.transactionKey = constants.transactionKey

	creditcard = apicontractsv1.creditCardType()
	creditcard.cardNumber = "4111111111111111"
	creditcard.expirationDate = "2020-12"

	payment = apicontractsv1.paymentType()
	payment.creditCard = creditcard

	#set profile information
	profile = apicontractsv1.customerProfileIdType()
	profile.customerProfileId = "121212";
	profile.customerPaymentProfileId = "131313";
	profile.customerAddressId = "141414";

	subscription = apicontractsv1.ARBSubscriptionType()
	subscription.payment = payment
	#to update customer profile information
	#subscription.profile = profile

	request = apicontractsv1.ARBUpdateSubscriptionRequest()
	request.merchantAuthentication = merchantAuth
	request.refId = "Sample"
	request.subscriptionId = subscriptionId
	request.subscription = subscription

	controller = ARBUpdateSubscriptionController(request)
	controller.execute()

	response = controller.getresponse()

	if (response.messages.resultCode=="Ok"):
	    print ("SUCCESS")
	    print ("Message Code : %s" % response.messages.message[0]['code'].text)
	    print ("Message text : %s" % response.messages.message[0]['text'].text)
	else:
	    print ("ERROR")
	    print ("Message Code : %s" % response.messages.message[0]['code'].text)
	    print ("Message text : %s" % response.messages.message[0]['text'].text)

	return response
merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = '5KP3u95bQpv'
merchantAuth.transactionKey = '4Ktq966gC55GAX7S'

creditcard = apicontractsv1.creditCardType()
creditcard.cardNumber = "4111111111111111"
creditcard.expirationDate = "2020-12"

payment = apicontractsv1.paymentType()
payment.creditCard = creditcard

subscription = apicontractsv1.ARBSubscriptionType()
subscription.payment = payment

request = apicontractsv1.ARBUpdateSubscriptionRequest()
request.merchantAuthentication = merchantAuth
request.refId = "Sample"
request.subscriptionId = "2945620"
request.subscription = subscription

controller = ARBUpdateSubscriptionController(request)
controller.execute()

response = controller.getresponse()

if (response.messages.resultCode == "Ok"):
    print "SUCCESS"
    print "Message Code : %s" % response.messages.message[0].code
    print "Message text : %s" % response.messages.message[0].text
else: