1

我正在关注 Payfort 文档(顺便说一句,这是非常非常糟糕的文档) https://docs.payfort.com/docs/mobile-sdk/build/index.html
将其集成到我的项目中,并且我已经使用 POST 来声明url 但我无法获得 sdk 令牌,我得到的只是一个没有正文的响应,所以如果有人能告诉我如何生成 sdk 令牌或我在以下代码中做错了什么。

这是对 POST 请求的响应

            Response{protocol=http/1.1, code=200, message=OK, url=https://sbpaymentservices.payfort.com/FortAPI/paymentApi}

这是我在 onFailure 回调中收到的消息

       E/Failure: {amount=100, response_code=00044, payment_option=VISA, order_description=DESCRIPTION, customer_ip=172.150.16.10, eci=ECOMMERCE, language=en, command=PURCHASE, response_message=Token name does not exist, sdk_token=sdk_token, merchant_reference=AGH-0008707682, customer_email=ghazalayah1995@yahoo.com, currency=SAR, customer_name=Sam, status=00}

, 这是代码

改造服务接口

     public interface Services {

@FormUrlEncoded
@Headers("Content-Type: application/json")
@POST("paymentApi")
Call<PayFortData> postRequest(@Field("language") String language,
                             @Field("device_id") String device_id,
                              @Field("service_command") String serviceCommand,
                              @Field("signature") String signature,
                              @Field("access_code") String access_code ,
                              @Field("merchant_identifier") String merchant_identifier);

}

PayFortActivity.class

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;

import com.payfort.fort.android.sdk.base.FortSdk;
import com.payfort.fort.android.sdk.base.callbacks.FortCallBackManager;
import com.payfort.fort.android.sdk.base.callbacks.FortCallback;
import com.payfort.sdk.android.dependancies.base.FortInterfaces;

import org.json.JSONObject;

      import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.util.HashMap;
  import java.util.Map;


  import retrofit2.Call;
  import retrofit2.Callback;
  import retrofit2.Response;
  import retrofit2.Retrofit;
  import retrofit2.converter.gson.GsonConverterFactory;

  import static com.payfort.sdk.android.dependancies.commons.Constants.FORT_PARAMS.SDK_TOKEN;

public class PayFortActivity extends AppCompatActivity {


private static final String TAG = "PayFortActivity.this";
private FortCallBackManager fortCallback = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pay_fort);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // create Fort callback instance
    fortCallback = FortCallback.Factory.create();

    Log.e( "onCreate: ", SDK_TOKEN);

    // Generating deviceId
    String deviceId = FortSdk.getDeviceId(PayFortActivity.this);
    Log.d("DeviceId ", deviceId);
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://sbpaymentservices.payfort.com/FortAPI/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    Services service = retrofit.create(Services.class);

    Call<PayFortData> repos = service.postRequest("ar",deviceId,SDK_TOKEN,
           "7cad05f0212ed933c9a5d5dffa31661acf2c827a" ,
            "zx0IPmPy5jp1vAz8Kpg7",
            "CycHZxVj");
    repos.enqueue(new Callback<PayFortData>() {
        @Override
        public void onResponse(Call<PayFortData> call, Response<PayFortData> response) {
            Log.e( "onResponse: ",response.toString() );
        }

        @Override
        public void onFailure(Call<PayFortData> call, Throwable t) {

        }
    } );





      //      prepare payment request
         FortRequest fortrequest = new FortRequest();
         fortrequest.setRequestMap(collectRequestMap(SDK_TOKEN));
         fortrequest.setShowResponsePage(true); // to [display/use] 
                       the SDK response page

   //      execute payment request
         callSdk(fortrequest);
     }





   private Map<String, String> collectRequestMap(String sdkToken) {
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("command", "PURCHASE");
    requestMap.put("customer_email", "ghazalayah1995@yahoo.com");
    requestMap.put("currency", "SAR");
    requestMap.put("amount", "100");
    requestMap.put("language", "en");
    requestMap.put("merchant_reference", "AGH-0008707682");
    requestMap.put("customer_name", "Sam");
    requestMap.put("customer_ip", "172.150.16.10");
    requestMap.put("payment_option", "VISA");
    requestMap.put("eci", "ECOMMERCE");
    requestMap.put("order_description", "DESCRIPTION");
    requestMap.put("sdk_token", sdkToken);
         return requestMap;
     }

     private void callSdk(FortRequest fortrequest) {

         try {
             FortSdk.getInstance().registerCallback(PayFortActivity.this,fortrequest,
                     FortSdk.ENVIRONMENT.TEST, 5, fortCallback, new FortInterfaces.OnTnxProcessed() {
                 @Override
                 public void onCancel(Map<String, String> requestParamsMap, Map<String,
                             String> responseMap) {
     //TODO: handle me
                         Log.d("Cancelled ", responseMap.toString());
                     }

                     @Override
                     public void onSuccess(Map<String, String> requestParamsMap, Map<String,
                             String> fortResponseMap) {
     //TODO: handle me
                         Log.i("Success ", fortResponseMap.toString());
                     }

                     @Override
                     public void onFailure(Map<String, String> requestParamsMap, Map<String,
                             String> fortResponseMap) {
     //TODO: handle me
                         Log.e("Failure ", fortResponseMap.toString());
                     }

                 });
             } catch (Exception e) {
                 Log.e("execute Payment", "call FortSdk", e);
             }

         }


         @Override
         public void onActivityResult(int requestCode, int resultCode, Intent data) {
             super.onActivityResult(requestCode, resultCode, data);
             fortCallback.onActivityResult(requestCode, resultCode, data);
         }


     }

支付宝数据

            package com.example.testat;

            import com.google.gson.annotations.Expose;
            import com.google.gson.annotations.SerializedName;

            /**
             * Created by agh on 26/02/18.
             */

            public class PayFortData {

                public String paymentResponse = "";
                //Response Params
                @SerializedName("access_code")
                @Expose
                public String accessCode;
                @SerializedName("sdk_token")
                @Expose
                public String sdkToken;
                @SerializedName("response_message")
                @Expose
                public String responseMessage;
                @SerializedName("status")
                @Expose
                public String status;
                @SerializedName("response_code")
                @Expose
                public String responseCode;
                @SerializedName("device_id")
                @Expose
                public String deviceId;
                @SerializedName("language")
                @Expose
                public String language;
                @SerializedName("service_command")
                @Expose
                public String serviceCommand;
                @SerializedName("signature")
                @Expose
                public String signature;
                @SerializedName("merchant_identifier")
                @Expose
                public String merchantIdentifier;


                @SerializedName("eci")
                @Expose
                public String eci;
                @SerializedName("card_number")
                @Expose
                public String cardNumber;
                @SerializedName("fort_id")
                @Expose
                public String fortId;
                @SerializedName("customer_email")
                @Expose
                public String customerEmail;
                @SerializedName("customer_ip")
                @Expose
                public String customerIp;
                @SerializedName("currency")
                @Expose
                public String currency;
                @SerializedName("amount")
                @Expose
                public String amount;
                @SerializedName("merchant_reference")
                @Expose
                public String merchantReference;
                @SerializedName("command")
                @Expose
                public String command;
                @SerializedName("payment_option")
                @Expose
                public String paymentOption;
                @SerializedName("expiry_date")
                @Expose
                public String expiryDate;
                @SerializedName("authorization_code")
                @Expose
                public String authorizationCode;

                public String getSdkToken() {
                    return sdkToken;
                }
            }
4

1 回答 1

0

该错误是因为您没有将之前保存的 sdk 令牌传递postRequest()给该callSdk()方法。

您应该在获得 sdk 令牌后调用callSdk()成功回调。postRequest

你不应该使用@FormUrlEncodedor @Field,你应该像这样在正文中传递请求参数:

@POST("paymentApi")
Call <FortTokenResponse> fortSdkToken(@Body FortTokenRequest payload);

其中FortTokenRequest包含身体参数。

FortTokenRequest.kt

data class FortTokenRequest(val service_command: String = "", 
                        val access_code: String = "",
                        val merchant_identifier: String = "",
                        val language: String = "", // en/ ar
                        val device_id: String = "",
                        val signature: String = "")
于 2018-02-27T16:57:44.757 回答