网站打不开dns修改,上海网络推广,潍坊网站建设wfxtseo,南宁手机网站制作介绍 在本节中#xff0c;我们将详细探讨如何使用网关并成功调用所有四种方法#xff0c;即购买#xff0c;退款#xff0c;作废和重新计费。 对于此示例#xff0c;我们将使用授权网关。 让我们开始。 首先#xff0c;我们将获得Authorize网关对象。 Gateway gateway… 介绍 在本节中我们将详细探讨如何使用网关并成功调用所有四种方法即购买退款作废和重新计费。 对于此示例我们将使用授权网关。 让我们开始。 首先我们将获得Authorize网关对象。 Gateway gateway GatewayFactory.getGateway(AvailableGateways.AUTHORIZE); 但是如果您想动态获取授权网关例如从数据库中获取其名称该怎么办。 这是您可以执行的操作。 Gateway gateway GatewayFactory.getGateway(AvailableGateways.valueOf(AUTHORIZE)); 知道您可以了解如何获取所需网关对象的两种方法。 由于我们在测试环境中工作因此第二件事就是启用测试模式。 gateway.setTestMode(true); 注意测试模式仅在网关支持的情况下才起作用否则它将被库忽略。 接下来最重要的是API参数这些是我的商家服务提供商提供的唯一值即API用户名和密码必须包含在所有请求中并且对于所有网关而言它们始终是不同的。 由于我们使用的是J2pay因此无需阅读任何文档即可授权网关变量。 这是您将使用样本参数方法的位置请参阅样本参数部分 这是您将如何做的。 JSONObject apiSampleParameters gateway.getApiSampleParameters(); 现在我们将打印它以查看参数是什么。 JSONObject apiSampleParameters gateway.getApiSampleParameters();System.out.println(apiSampleParameters);//output{ name : also called api user name / api login id, transactionKey : the transaction key } 如您所见对于Authorize API参数是name和transactionKey。 我们将填充这些值并传递给购买方法。 apiSampleParameters.put(name, your acounts user name here);
apiSampleParameters.put(transactionKey, your accounts transaction key here);采购 购买方法需要五个参数。 JSONObject apiParamters这是网关特定的参数对于每个网关而言始终是唯一的。 客户客户这个类代表客户的个人信息。 CustomerCard customerCard此类代表客户卡详细信息。 货币货币即枚举包含将收取金额的货币列表。 浮动金额将要收取的金额。 我们已经在上面设置了apiParameters。 现在创建客户和客户卡对象。 注意客户和客户卡类支持链设置器方法并且下面使用的所有字段都是必需的。 Customer customer new Customer();customer.setFirstName(test first name).setLastName(test last name).setCountry(Country.US).setState(TX).setCity(test city).setAddress(test address).setZip(12345).setPhoneNumber(1234567890).setEmail(emaildomain.com).setIp(127.0.0.1);CustomerCard customerCard new CustomerCard();customerCard.setName(test card name).setNumber(5424000000000015).setCvv(123).setExpiryMonth(01).setExpiryYear(2022); 注意第4和第5参数不需要任何解释。 现在所有参数都准备好了我们可以将它们传递给购买方法 HTTPResponse response gateway.purchase(apiSampleParameters, customer, customerCard, Currency.USD, 45); 您可以通过调用isSuccessful方法来检查购买请求的状态还可以通过调用getJSONResponse方法来获取JSON响应。 response.isSuccessful();response.getJSONResponse(); 让我们将所有代码放在一起。 Gateway gateway GatewayFactory.getGateway(AvailableGateways.AUTHORIZE);JSONObject apiSampleParameters gateway.getApiSampleParameters();apiSampleParameters.put(name, );apiSampleParameters.put(transactionKey, );Customer customer new Customer();customer.setFirstName(test first name).setLastName(test last name).setCountry(Country.US).setState(TX).setCity(test city).setAddress(test address).setZip(12345).setPhoneNumber(1234567890);CustomerCard customerCard new CustomerCard();customerCard.setName(test card name).setNumber(5424000000000015).setCvv(123).setExpiryMonth(01).setExpiryYear(2022);gateway.setTestMode(true);HTTPResponse response gateway.purchase(apiSampleParameters, customer, customerCard, Currency.USD, 45);System.out.println (response.isSuccessful());System.out.println (response.getJSONResponse()); 让我们看看收到的回复。 考虑我们将响应保存在响应变量中。 JSONObject response response.getJSONResponse(); 打印响应后这就是我们得到的。 {lr: {amount: 2.5,cardExpiryYear: 2017,message: This transaction has been approved.,cardFirst6: 542400,cardExpiryMonth: 12,transactionId: 60036012175,maskedCard: 542400******0015,rebillParams: {customerProfileId: 1813844918,paymentProfileId: 1808509554},success: true,voidParams: {transactionId: 60036012175},currencyCode: USD,cardLast4: 0015,refundParams: {transactionId: 60036012175,cardLast4: 0015}},gr: { //long gateway response }} 如您所见对于进一步的交易如退款作废或重新开票图书馆本身创建了必需的参数 重新开票 rebillParams: {customerProfileId: 1813844918,paymentProfileId: 1808509554}, 虚无 voidParams: {transactionId: 60036012175}, 退款 refundParams: {transactionId: 60036012175,cardLast4: 0015} 注意您可以将这些参数保存在数据库中并将它们传递给合适的方法。 重新开票 对于重新计费我们将调用getRebillSampleParameters方法。 JSONObject rebillSampleParameters gateway.getRebillSampleParameters(); 打印后您将看到。 {customerProfileId:the customer profile id,paymentProfileId:the customer payment profile id} 如果将其与上面的购买响应rebillParams密钥相匹配您将看到实际上没有任何区别。 购买响应已经包含这些参数以及填充的值。 因此我们不会像上面的getApiSampleParameters那样创建它们但是如果您尚未从该库中执行购买交易则可以使用第二个选项来创建这些参数并将它们传递给rebill方法。 下面我们描述了两种方法因此您可以使用更适合自己的方法。 第一种方法 这种方法是快速前进的。 我们将使用库生成的参数rebillParams。 由于重新开票方法需要三个参数 JSON apiParameters JSON rebillParameters 浮动金额 我们已经讨论了apiParameters只是提醒您我们将网关对象保存在网关变量中并将购买响应保存在响应变量中。 这是我们可以轻松调用rebill方法的方法。 JSONObject rebillParams response.getJSONObject(lr).getJSONObject(rebillParams)HTTPResponse rebillResponse gateway.rebill(apiSampleParameters, rebillParams, 105); 仅仅两行就不是那么简单吗 第二种方法 第二种方法与我们创建的apiParameters类似。 JSONObject rebillParams gateway.getRebillSampleParameters(); 打印rebillParams之后我们得到了。 System.out.println(rebillParams);//output{customerProfileId:the customer profile id,paymentProfileId:the customer payment profile id} 现在我们将填充这些值。 rebillParams.put(customerProfileId, 1813844918);rebillParams.put(paymentProfileId, 1808509554); 现在我们可以调用rebill方法。 HTTPResponse rebillResponse gateway.rebill(apiSampleParameters, rebillParams, 105); 如上所示您可以调用rebillResponse。 getJSONResponse方法获取响应。 您还可以通过调用rebillResponse.isSuccessful方法来检查事务是否成功。 您还可以注意到这两种方法都非常简单可以随意使用更适合自己的方法但是建议您使用第一种方法因为这也非常简单并且排除了任何可能的错误。 注意在本示例的其余部分我们将使用第一种方法。 退款 退款方式需要三个参数 JSON apiParameters JSON退款参数 浮动金额 这与退款非常相似。 这就是我们称为退款方式的方式。 JSONObject refundParams response.getJSONObject(lr).getJSONObject(refundParams)HTTPResponse refundResponse gateway.refund(apiSampleParameters, refundParams, 2.5); 注意其余工作将保持不变returnResponse包含实际的响应。 空洞 voidTransaction方法需要两个参数。 JSON apiParameters JSON voidParameters 下面是示例代码。 JSONObject voidParams response.getJSONObject(lr).getJSONObject(voidParams)HTTPResponse voidResponse gateway.voidTransaction (apiSampleParameters, voidParams); 注意其余工作将保持不变voidResponse包含实际的响应。 祝贺您完成示例。 您已经完全了解该库。 翻译自: https://www.javacodegeeks.com/2018/11/j2pay-complete-example.html