区块链技术博客
www.b2bchain.cn

Authorize—支付

这篇文章主要介绍了Authorize—支付的讲解,通过具体代码实例进行16229 讲解,并且分析了Authorize—支付的详细步骤与相关技巧,需要的朋友可以参考下https://www.b2bchain.cn/?p=16229

本文实例讲述了2、树莓派设置连接WiFi,开启VNC等等的讲解。分享给大家供大家参考文章查询地址https://www.b2bchain.cn/7039.html。具体如下:

文章目录

  • 1、前置
  • 2、准备工作
    • 1、MANEV包:
    • 2、获取 NAME 和 TRANSACTION_KEY, 登录地址: https://account.authorize.net/
    • 3、订单界面
    • 4、配置结算时间
  • 3、创建订单并支付:
  • 4、申请退款:
  • 5、查询订单:
  • 6:杂谈


1、前置

1、美国项目的一个支付, 这是一个非常优秀的支付, 文档简洁明了, 思路清晰, 接入起来特别让人省心, 尤其是客服真的很棒, 很耐心, 很亲和的感觉, 比起其余的支付这个真的很赞! 官网地址:https://developer.authorize.net/

2、案列采用java编写

3、介绍Authorize订单整合:
      https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card

4、会对一些可能出现的坑,或者说我碰到的坑进行标记

5、介最后贴图验证以及做好后的样子

6、Payment Transactions(支付), Refund a Transaction(退款), Get Transaction Details(查询).
当然他也有捕获和授权操作, 这个没有写, 和前几篇博客差不多

7、代码已上传码云,如果起到帮助还请star一下地址:https://gitee.com/xmaxm/payments_hodgepodge

8、沙箱注册地址:
https://developer.authorize.net/hello_world/sandbox.html

2、准备工作

1、MANEV包:

<!-- authorize支付 --> <dependency>     <groupId>net.authorize</groupId>     <artifactId>anet-java-sdk</artifactId>     <version>LATEST</version> </dependency> 

2、获取 NAME 和 TRANSACTION_KEY, 登录地址: https://account.authorize.net/

再注册的时候就会有, 如果没有参考如下截图:
Authorize---支付

3、订单界面

Authorize---支付
Voided: 这个是Void a Transaction, 无效的交易, 我手动处理的

明天再补充一个截图
Authorize---支付

4、配置结算时间

Authorize---支付

3、创建订单并支付:

地址:https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card

public CommonResult authorizePay(String orderNo) {         // 设置环境沙盒或生产         if (true) {             ApiOperationBase.setEnvironment(Environment.SANDBOX);         } else {             ApiOperationBase.setEnvironment(Environment.PRODUCTION);         }         // 创建带有商家身份验证详细信息的对象         MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();         merchantAuthenticationType.setName(name);         merchantAuthenticationType.setTransactionKey(transactionKey);          // 填充付款数据         PaymentType paymentType = new PaymentType();         CreditCardType creditCard = new CreditCardType();         creditCard.setCardNumber("5424000000000015");         creditCard.setExpirationDate("2020-12");         creditCard.setCardCode("999");         paymentType.setCreditCard(creditCard);          // 设置电子邮件地址(可选)         CustomerDataType customer = new CustomerDataType();         customer.setEmail("[email protected]");          // 创建付款交易对象         TransactionRequestType txnRequest = new TransactionRequestType();         // 信用卡充值         txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());         txnRequest.setPayment(paymentType);         txnRequest.setCustomer(customer);         txnRequest.setCurrencyCode(currency);         // 商家分配的采购订单号. 字符串,最多25个字符。         txnRequest.setPoNumber(orderNo);         txnRequest.setAmount(new BigDecimal(200).setScale(2, RoundingMode.CEILING));          //创建API请求并为此特定请求设置参数         CreateTransactionRequest apiRequest = new CreateTransactionRequest();         apiRequest.setMerchantAuthentication(merchantAuthenticationType);         apiRequest.setTransactionRequest(txnRequest);         // 商家为请求分配的参考ID. 字符串,最多20个字符。         apiRequest.setRefId(orderNo);          // 呼叫控制器         CreateTransactionController controller = new CreateTransactionController(apiRequest);         controller.execute();          // 得到回应         CreateTransactionResponse response = controller.getApiResponse();          log.info("authorize 支付操作返回结果: " + JSONObject.toJSONString(response));          // 解析响应以确定结果         if (response != null) {             // 如果API响应正常,请继续检查事务响应             if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {                 TransactionResponse result = response.getTransactionResponse();                 if (result.getMessages() != null) {                     return CommonResult.success("SUCCESS", result.getTransId());                 } else {                     if (response.getTransactionResponse().getErrors() != null) {                         return CommonResult.failMessage(500, "Authorize 支付失败", result.getErrors().getError().get(0).getErrorText());                     }                 }             } else {                 if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {                     return CommonResult.failMessage(500, "Authorize 支付异常", response.getTransactionResponse().getErrors().getError().get(0).getErrorText());                 } else {                     return CommonResult.failMessage(500, "Authorize 支付异常", response.getMessages().getMessage().get(0).getText());                 }             }         } else {             // 响应为空时显示错误代码和消息             ANetApiResponse errorResponse = controller.getErrorResponse();             if (!errorResponse.getMessages().getMessage().isEmpty()) {                 return CommonResult.failMessage(500, "Authorize 支付异常", errorResponse.getMessages().getMessage().get(0).getText());             }         }         return CommonResult.fail(500, "NetworkTimeout");     } 
authorize 支付操作返回结果: {"messages":{"message":[{"code":"I00001","text":"Successful."}],"resultCode":"OK"},"refId":"20201109793223","transactionResponse":{"accountNumber":"XXXX0015","accountType":"MasterCard","authCode":"1HN636","avsResultCode":"Y","cavvResultCode":"2","cvvResultCode":"P","messages":{"message":[{"code":"1","description":"This transaction has been approved."}]},"networkTransId":"2B8VVTWHC0WYKKEV9RGC3R2","refTransID":"","responseCode":"1","testRequest":"0","transHash":"","transHashSha2":"","transId":"40056262861"}} 

4、申请退款:

地址:https://developer.authorize.net/api/reference/index.html#payment-transactions-refund-a-transaction

public CommonResult authorizeRefund(String amount, String transId) {         // 设置环境沙盒或生产         if (true) {             ApiOperationBase.setEnvironment(Environment.SANDBOX);         } else {             ApiOperationBase.setEnvironment(Environment.PRODUCTION);         }         // 创建带有商家身份验证详细信息的对象         MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();         merchantAuthenticationType.setName(name);         merchantAuthenticationType.setTransactionKey(transactionKey);          // 填充退款数据         PaymentType paymentType = new PaymentType();         CreditCardType creditCard = new CreditCardType();         String bankCard = "5424000000000015";         creditCard.setCardNumber(bankCard.substring(bankCard.length() - 4));         creditCard.setExpirationDate("XXXX");         paymentType.setCreditCard(creditCard);          // 创建付款交易对象         TransactionRequestType txnRequest = new TransactionRequestType();         txnRequest.setTransactionType(TransactionTypeEnum.REFUND_TRANSACTION.value());         txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));         txnRequest.setPayment(paymentType);         txnRequest.setRefTransId(transId);          //创建API请求并为此特定请求设置参数         CreateTransactionRequest apiRequest = new CreateTransactionRequest();         apiRequest.setMerchantAuthentication(merchantAuthenticationType);         apiRequest.setTransactionRequest(txnRequest);          // 呼叫控制器         CreateTransactionController controller = new CreateTransactionController(apiRequest);         controller.execute();          // 得到回应         CreateTransactionResponse response = controller.getApiResponse();          log.info("authorize 退款操作返回结果: " + JSONObject.toJSONString(response));          // 解析响应以确定结果         if (response != null) {             // 如果API响应正常,请继续检查事务响应             if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {                 TransactionResponse result = response.getTransactionResponse();                 if (result.getMessages() != null) {                     return CommonResult.success("SUCCESS", result.getTransId());                 } else {                     if (response.getTransactionResponse().getErrors() != null) {                         return CommonResult.failMessage(500, "Authorize 申请退款失败", result.getErrors().getError().get(0).getErrorText());                     }                 }             } else {                 if (response.getTransactionResponse() != null && response.getTransactionResponse().getErrors() != null) {                     return CommonResult.failMessage(500, "Authorize 申请退款异常", response.getTransactionResponse().getErrors().getError().get(0).getErrorText());                 } else {                     return CommonResult.failMessage(500, "Authorize 申请退款异常", response.getMessages().getMessage().get(0).getText());                 }             }         } else {             // 响应为空时显示错误代码和消息             ANetApiResponse errorResponse = controller.getErrorResponse();             if (!errorResponse.getMessages().getMessage().isEmpty()) {                 return CommonResult.failMessage(500, "Authorize 申请退款异常", errorResponse.getMessages().getMessage().get(0).getText());             }         }         return CommonResult.fail(500, "NetworkTimeout");     } 
今天退款不了, 明天再补充吧 在这里插入代码片 

5、查询订单:

地址:https://developer.authorize.net/api/reference/index.html#transaction-reporting-get-transaction-details

public CommonResult authorizeQuery(String transId) {         // 设置环境沙盒或生产         if (true) {             ApiOperationBase.setEnvironment(Environment.SANDBOX);         } else {             ApiOperationBase.setEnvironment(Environment.PRODUCTION);         }         // 创建带有商家身份验证详细信息的对象         MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();         merchantAuthenticationType.setName(name);         merchantAuthenticationType.setTransactionKey(transactionKey);                  GetTransactionDetailsRequest getRequest = new GetTransactionDetailsRequest();         getRequest.setMerchantAuthentication(merchantAuthenticationType);         getRequest.setTransId(transId);          GetTransactionDetailsController controller = new GetTransactionDetailsController(getRequest);         controller.execute();          // 得到回应         GetTransactionDetailsResponse response = controller.getApiResponse();          log.info("authorize 查询操作返回结果: " + JSONObject.toJSONString(response));          if (response != null) {             if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {                 return CommonResult.success("SUCCESS", response.getMessages().getMessage().get(0).getText());             } else {                 log.error("authorize 查询订单未能获取信息:  {}", response.getMessages().getResultCode());                 return CommonResult.failMessage(500, "Authorize 支付查询失败", response.getMessages().getResultCode());             }         }         return CommonResult.fail(500, "NetworkTimeout");     } 
支付成功后查询: authorize 查询操作返回结果: {"clientId":"sdk-java-2.0.1","messages":{"message":[{"code":"I00001","text":"Successful."}],"resultCode":"OK"},"transaction":{"aVSResponse":"Y","authAmount":200.00,"authCode":"1HN636","cardCodeResponse":"P","customer":{"email":"[email protected]"},"customerIP":"171.113.166.111","marketType":"eCommerce","order":{"discountAmount":0,"purchaseOrderNumber":"20201109793223","taxIsAfterDiscount":false},"payment":{"creditCard":{"cardNumber":"XXXX0015","cardType":"MasterCard","expirationDate":"XXXX"}},"product":"Card Not Present","recurringBilling":false,"responseCode":1,"responseReasonCode":1,"responseReasonDescription":"Approval","settleAmount":200.00,"submitTimeLocal":1604865630560,"submitTimeUTC":1604923230560,"taxExempt":false,"transId":"40056262861","transactionStatus":"capturedPendingSettlement","transactionType":"authCaptureTransaction"},"transrefId":"20201109793223"}  退款成功后查询:  

6:杂谈

1、很简单的一个支付, 客服给人的感觉很有亲和力!

2、基于订单的状态码:
Thank you for holding. First, regarding the automatic question, yes settlement with Authorize.Net happens once a day automatically. This process begins at your “Transaction Cut off time”. Currently that is set to: 4:00 PM PDT.
This can however vary depending on the Transaction status. If its “Captured/ Pending Settlement”. Thats great, its automatic. But for all other statuses, here is a support article that explains what they mean in case you need to take an action:
https://support.authorize.net/s/article/What-Are-the-Possible-Transaction-Statuses

3、交易截止时间如何设置? 也就是自动结算的意思
Well, the Transaction cut off time, just means when we begin to report your activity for funding. All new accounts have this set to 4PM Pacific time. But you can change this setting by following these steps:
-Click Account from the main toolbar.
-Click Settings from the main left side menu.
-Click Transaction Cut-Off Time near the bottom of the page.
-Click Edit.
-Select the desired Transaction Cut-Off Time.
-Click Submit.
NOTE: Changing the Transaction Cut-Off Time may delay settlement of the current batch by one day if the new time is less than 24 hours from the last settlement.

4、代码上传码云地址:https://gitee.com/xmaxm/payments_hodgepodge

5、需要配置结算时间, 他们不是实时结算, 一天为一个结算时间, 所以如果当天订单需要退款, 调用第4步的申请退款是会失败的,
可以参考这个API:https://developer.authorize.net/api/reference/index.html#payment-transactions-void-a-transaction

6、没有结算的订单就进行退款, 是会失败的, 只有结算的订单才可以进行退款操作

7、捕获和授权的流程, 如果不清楚, 可以参考我支付系列的文章PayPal支付

8、官方GitHub: https://github.com/search?utf8=%E2%9C%93&q=org%3AAuthorizeNet+sample&type=Repositories&ref=searchresults

提供一个群:807770565,欢迎各位进来尬聊 (人不多, 进了就不要退了, 要不就不进, 跪求留一点人, 人多了就活跃了, 跪谢)
Authorize---支付

本文转自互联网,侵权联系删除Authorize—支付

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Authorize—支付
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们