def accept_claim(self, dispute_id: str, refund_amount: Money = None, **kwargs) -> PaypalApiBulkResponse[ActionLink]: """Calls the paypal API to accept a claim & close the dispute in favor of the customer Arguments: dispute_id {str} -- [description] Keyword Arguments: note {str} -- Notes & comments accept_claim_reason {str} -- Reason to accept the claim (default REASON_NOT_SET) invoice_id {str} -- The merchant-provided ID of the invoice for the refund. return_shipping_address {PaypalPortableAddress} -- The return address for the item. refund_amount {Money} -- To accept a customer's claim, the amount that the merchant agrees to refund the customer. Returns: PaypalApiBulkResponse[ActionLink] -- action links related to the dispute """ if refund_amount: kwargs['refund_amount'] = refund_amount.to_dict() self._remove_null_entries(kwargs['refund_amount']) if 'return_shipping_address' in kwargs.keys() and isinstance( kwargs['return_shipping_address'], PaypalPortableAddress): kwargs['return_shipping_address'] = kwargs[ 'return_shipping_address'].to_dict() self._remove_null_entries(kwargs['return_shipping_address']) return self._execute_basic_dispute_action( parse_url(self._base_url, dispute_id, 'accept-claim'), kwargs)
def capture_authorized_payment( self, authorization_id: str, invoice_id: str = None, note_to_payer: str = None, instruction: PaymentInstruction = None, amount: Money = None, final_capture: bool = False, request_id: str = None, response_type: ResponseType = ResponseType.MINIMAL ) -> PaypalApiResponse[Capture]: """Calls the paypal API to capture an authorized payment, by ID. Arguments: authorization_id {str} -- authorization id invoice_id {str} -- associated invoice note_to_payer {str} -- informational notes about the settlement. Appears in the payer's transaction history and received emails. Keyword Arguments: instruction {PaymentInstruction} -- Any additional payment instructions for PayPal for Partner customers (default: {None}) amount {Money} -- The amount to capture. If none the full amount will be captured (default: {None}). final_capture {bool} -- dictates whether you can make additional captures against the authorized payment (default: {False}). request_id {str} -- Paypal request id for idempotence (default: {None}) response_type {ResponseType} -- desired response type (default: {ResponseType.MINIMAL}) Returns: PaypalApiResponse[Authorization] -- An api response with the authorization details """ body = dict() url = parse_url(self._base_url, authorization_id, 'capture') headers = {'Prefer': response_type.as_header_value()} if request_id: headers['PayPal-Request-Id'] = request_id if invoice_id: body['invoice_id'] = invoice_id if note_to_payer: body['note_to_payer'] = note_to_payer if final_capture: body['final_capture'] = final_capture if instruction: body['instruction'] = instruction if amount: body['amount'] = amount.to_dict() api_response = self._session.post(url, json.dumps(body), headers=headers) if api_response.status_code != 201: return PaypalApiResponse(True, api_response) return PaypalApiResponse( False, api_response, Capture.serialize_from_json(api_response.json()))
def refund_capture( self, capture_id: str, invoice_id: str, note_to_payer: str, amount: Money = None, request_id: str = None, auth_assertion_token: str = None, response_type: ResponseType = ResponseType.MINIMAL ) -> PaypalApiResponse[Refund]: """Calls the api to refund a capture Arguments: capture_id {str} -- capture identifier invoice_id {str} -- invoice related capture note_to_payer {str} -- notes to the customer Keyword Arguments: amount {Money} -- amount to be refunded if None then 'captured amount - previous refunds' (default: {None}) request_id {str} -- request id for idempotence (default: {None}) auth_assertion_token {str} -- auth assertion token. See paypal header docs (default: {None}) response_type {ResponseType} -- response type. See paypal header docs (default: {ResponseType.MINIMAL}) Returns: PaypalApiResponse[Refund] -- api response with refund details """ body = dict() url = parse_url(self._base_url, capture_id, 'refund') headers = {'Prefer': response_type.as_header_value()} if request_id: headers['PayPal-Request-Id'] = request_id if auth_assertion_token: headers['PayPal-Auth-Assertion'] = auth_assertion_token if invoice_id: body['invoice_id'] = invoice_id if note_to_payer: body['note_to_payer'] = note_to_payer if amount: body['amount'] = amount.to_dict() api_response = self._session.post(url, json.dumps(body), headers=headers) if api_response.status_code != 201: return PaypalApiResponse(True, api_response) return PaypalApiResponse( False, api_response, Refund.serialize_from_json(api_response.json()))
def make_return_offer( self, dispute_id: str, note: str, offer_type: str, invoice_id: str = None, offer_amt: Money = None, return_addr: PaypalPortableAddress = None ) -> PaypalApiBulkResponse[ActionLink]: """Calls the API to make an offer to the other party to resolve a dispute Arguments: dispute_id {str} -- The dispute identifier note {str} -- Customer notes about the escalation offer_type {str} -- The merchant-proposed offer type for the dispute Keyword Arguments: offer_amt {Money} -- The amount proposed to resolve the dispute. invoice_id {str} -- The merchant-provided ID of the invoice for the refund. return_shipping_address {PaypalPortableAddress} -- The return address for the item. refund_amount {Money} -- To accept a customer's claim, the amount that the merchant agrees to refund the customer. Returns: PaypalApiBulkResponse[ActionLink] -- action links related to the dispute """ body = {'note': note, 'offer_type': offer_type} if invoice_id: body['invoice_id'] = invoice_id if offer_amt: body['offer_amount'] = offer_amt.to_dict() self._remove_null_entries(body['offer_amount']) if return_addr: body['return_address'] = return_addr.to_dict() self._remove_null_entries(body['return_address']) return self._execute_basic_dispute_action( parse_url(self._base_url, dispute_id, 'make-offer'), body)
def capture_authorized_payment_on_subscription( self, subscription_id: str, note: str, amount: Money, capture_type: str = 'OUTSTANDING_BALANCE', request_id: str = None) -> PaypalApiResponse[Capture]: """ Calls the Paypal API to perform a capture on an authorized payment from the subscriber on the subscription. Arguments: subscription_id {str} -- the subscription id note {str} -- The reason or note for the subscription charge. amount {Money} -- The amount of the outstanding balance. Must not be greater than the current outstanding balance amount. Returns: PaypalApiResponse[Capture] -- A response with a capture """ url = parse_url(self._base_url, subscription_id, 'capture') body = json.dumps({ 'note': note, 'amount': amount.to_dict(), 'capture_type': capture_type }) if not request_id: api_response = self._session.post(url, body) else: api_response = self._session.post( url, body, headers={'PayPal-Request-Id': request_id}) if api_response.status_code // 100 != 2: return PaypalApiResponse.error(api_response) j_data = api_response.json() return PaypalApiResponse.success( api_response, Capture.serialize_from_json(j_data) if j_data else None)
def reauthorize_payment( self, authorization_id: str, amount: Money, request_id: str = None, response_type: ResponseType = ResponseType.MINIMAL ) -> PaypalApiResponse[Authorization]: """Calls the paypal API to reauthorize an authorized payment, by ID. See the api docs for a full set of rules. Arguments: authorization_id {str} -- The authorization id amount {Money} -- The amount to reauthorize for an authorized payment. Returns: PaypalApiResponse[Authorization] -- An api response with the authorization details """ body = dict() url = parse_url(self._base_url, authorization_id, 'reauthorize') headers = {'Prefer': response_type.as_header_value()} if request_id: headers['PayPal-Request-Id'] = request_id if amount: body['amount'] = amount.to_dict() api_response = self._session.post(url, json.dumps(body), headers=headers) if api_response.status_code != 201: return PaypalApiResponse(True, api_response) return PaypalApiResponse( False, api_response, Authorization.serialize_from_json(api_response.json()))