Issuing a Refund

Refunds may be issued with or without a reference id. Naturally, less data needs to be entered when a referenced refund is executed.

Keyed Refund example:

final KeyedTransaction transaction = new AnyPayTransaction();
transaction.setTransactionType(TransactionType.REFUND);
transaction.setTotalAmount(new Amount("20.25"));
transaction.setCardExpiryMonth("10");
transaction.setCardExpiryYear("20");
transaction.setAddress("123 Main Street");
transaction.setPostalCode("30004");
transaction.setCVV2("999");
transaction.setCardholderName("Jane Doe");
transaction.setCardNumber("4012888888881881");
transaction.execute(transactionListener);
// transaction has to be initialized with initWithType:ANPTransactionType_REFUND
transaction.totalAmount = [ANPAmount amountWithString:self.textField.text];
transaction.cardExpiryMonth = @"12";
transaction.cardExpiryYear = @"20";
transaction.cardType = @"VISA";
transaction.cardNumber = @"4111111111111111";
transaction.cardHolderName = @"Jane Dough";
transaction.CVV2 = @"123";
    
[transaction execute:^(ANPTransactionStatus status, ANPMeaningfulError * _Nullable error) {
  if (status == ANPTransactionStatus_APPROVED) {
    NSLog(@"Unref Transaction APPROVED");
    [self appendText:[NSString stringWithFormat:@"\n\n Unref Refund Transaction Approved"]];
  }
  else if (status == ANPTransactionStatus_DECLINED) {
    NSLog(@"Unref Transaction DECLINED");
    [self appendText:[NSString stringWithFormat:@"\n\n Unref Refund Transaction DECLINED"]];
  }
  else {
    NSLog(@"Unref Transaction Failed");
    [self appendText:[NSString stringWithFormat:@"\n\n Unref Refund Transaction Failed -- %@", error.message]];
  }
}];

Referenced Refund example:

// using a reference transaction
String referenceId = "[valid refence id]";

final AnyPayReferenceTransaction transaction = new AnyPayReferenceTransaction();
transaction.setTotalAmount(new Amount("0.05"));
transaction.setTransactionType(TransactionType.REFUND);
transaction.setExternalId(referenceId);
transaction.execute(transactionListener);
// transaction initialized with initWithType:ANPTransactionType_REFUND
transaction.externalID = @"L6O4NI27C1";//IFA9XX8B7M
transaction.totalAmount = [ANPAmount amountWithDouble:0.89];

[transaction execute:^(ANPTransactionStatus status, ANPMeaningfulError * _Nullable error) {
  if (status == ANPTransactionStatus_APPROVED) {
    NSLog(@"Ref Transaction APPROVED");
    [self appendText:[NSString stringWithFormat:@"\n\n Ref Refund Transaction Approved"]];
  }
  else if (status == ANPTransactionStatus_DECLINED) {
    NSLog(@"Ref Transaction DECLINED");
    [self appendText:[NSString stringWithFormat:@"\n\n Ref Refund Transaction DECLINED"]];
  }
  else {
    NSLog(@"Ref Transaction Failed");
    [self appendText:[NSString stringWithFormat:@"\n\n Ref Refund Transaction Failed -- %@", error.message]];
  }
}];