2014-04-04 47 views
2

我在PayPal中創建帳戶,並且我已經下載了Paypal sdk。我已經提出申請,並從網站獲得客戶端ID。現在,我無法通過開發人員ID登錄到PayPal網關後,我的應用程序集成。無法通過開發人員在PayPal登錄用戶名密碼

請幫我,我要去哪裏錯了

我的代碼

try{ 
    Double amount=Double.parseDouble(amnt.getText().toString()); 
    if(amount>=62 && amount!=null && amount!=0.0){ 
    amount=amount/62; 
    PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(""+amount), "USD", "Cab Rent");   
    Intent intent = new Intent(this, PaymentActivity.class); 

    intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
    intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL); 

    // It's important to repeat the clientId here so that the SDK has it if Android restarts your 
    // app midway through the payment UI flow. 
    intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "AXJjcRB6yUtJghGBgdDHmOgkL8a9Jnd0RVARU9XPGqZ_lSstEhDSkh7D9AL2"); 
    intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "");//from ui we have to design 
    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy); 

    startActivityForResult(intent, 0); 
     } 
     else{ 
      Toast.makeText(getApplicationContext(), " An invalid payment was submitted. 1$ minimum", Toast.LENGTH_LONG).show(); 
     }} 
    catch(Exception e){ 
     Log.d("Paypal_Activity", ""+e); //BLUE 

    } 

上的活動結果

@Override 
protected void onActivityResult (int requestCode, int resultCode, Intent data) { 
    if (resultCode == Activity.RESULT_OK) { 
     PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION); 
     if (confirm != null) { 
      try { 
       Log.i("paymentExample", confirm.toJSONObject().toString(4)); 

       // TODO: send 'confirm' to your server for verification. 
       // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ 
       // for more details. 

      } catch (JSONException e) { 
       Log.e("paymentExample", "an extremely unlikely failure occurred: ", e); 
      } 
     } 
    } 
    else if (resultCode == Activity.RESULT_CANCELED) { 
     Log.i("paymentExample", "The user canceled."); 
    } 
    else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) { 
     Log.i("paymentExample", "An invalid payment was submitted. Please see the docs."); 
    } 
} 

enter image description here

+0

它看起來並不像你所使用的SDK的最新版本。我建議你這樣做(對你的整合稍做改動)。 –

回答

0

從這個頁面:PayPal MPL for android returns error ID 589023

貝寶錯誤589023尤其是有這個意思:

If a fractional amount is rounded due to currency conversion, funds could be lost 

也許你沒有四捨五入向上/向下到最小單位或貨幣美分。

例如:

(amount* fee_multiplier).round(2) 

更新: 值如$ 1.1和$ 1.111是不可接受由貝寶。我們需要確保thingToBuy中收到的值已經四捨五入到最接近的美分和貨幣的最低單位。

又如:

DecimalFormat df = new DecimalFormat("#.00"); 
df.format(amount); 

結果:

amount: 1.3333333 (double) -> df.format: 1.33 (new DecimalFormat) 

貨幣像印尼盾(IDR)沒有任何小數,因爲它們的最小單位是IDR 25

+0

更早(前8個月)我使用相同的代碼,交易成功完成 – Yushi

+0

你有沒有嘗試在發送到貝寶之前顯示真實的金額?價格如$ 12.909(例如)不被Paypal接受。 –

+0

用於測試沙盒模式的CVV是什麼? – Yushi

2

嘿,這是我的工作代碼與我的應用程序給定的憑據...

The Bu yActivity.java

package com.example.paypalintegration; 

import java.math.BigDecimal; 

import org.json.JSONException; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.Toast; 

import com.paypal.android.sdk.payments.PayPalPayment; 
import com.paypal.android.sdk.payments.PayPalService; 
import com.paypal.android.sdk.payments.PaymentActivity; 
import com.paypal.android.sdk.payments.PaymentConfirmation; 

public class BuyActivity extends Activity { 

    private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_NO_NETWORK; 
    private static final String CONFIG_CLIENT_ID = "AFcWxV21C7fd0v3bYYYRCpSSRl31AR.aAFjBsPf7PzEUNdhcCM3xDQBN"; 
    private static final String CONFIG_RECEIVER_EMAIL = "[email protected]"; 
    private EditText amnt; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_buy); 
     amnt=(EditText)findViewById(R.id.editText1); 
     Intent intent = new Intent(this, PayPalService.class); 

     intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
     intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
     intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL); 

     startService(intent); 
    } 

    public void onBuyPressed(View pressed) { 
     Double amount=Double.parseDouble(amnt.getText().toString()); 
     if(amount>=62 && amount!=null && amount!=0.0){ 
     amount=amount/62; 
     } 
     PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(String.valueOf(amount)), "NOK","Cab Rent"); 

     Intent intent = new Intent(this, PaymentActivity.class); 

     intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT); 
     intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID); 
     intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL); 
     intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy); 

     startActivityForResult(intent, 0); 
    } 

    @Override 
    protected void onActivityResult (int requestCode, int resultCode, Intent data) { 
     if (resultCode == Activity.RESULT_OK) { 
      PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION); 
      if (confirm != null) { 
       try { 
        Log.i("paymentExample", confirm.toJSONObject().toString(4)); 

        // TODO: send 'confirm' to your server for verification. 
        // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ 
        // for more details. 
        Toast.makeText(this,confirm.toJSONObject().toString(4),Toast.LENGTH_LONG).show(); 
       } catch (JSONException e) { 
        Log.e("paymentExample", "an extremely unlikely failure occurred: ", e); 
       } 
      } 
     } 
     else if (resultCode == Activity.RESULT_CANCELED) { 
      Log.i("paymentExample", "The user canceled."); 
      Toast.makeText(this,"The user canceled.",Toast.LENGTH_LONG).show(); 
     } 
     else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) { 
      Log.i("paymentExample", "An invalid payment was submitted. Please see the docs."); 
      Toast.makeText(this,"An invalid payment was submitted. Please see the docs.",Toast.LENGTH_LONG).show(); 
     } 
    } 

    @Override 
    public void onDestroy() { 
     stopService(new Intent(this, PayPalService.class)); 
     super.onDestroy(); 
    } 
} 

XML文件activity_buy.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <Button 
     android:id="@+id/buyItBtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:onClick="onBuyPressed" 
     android:text="Buy this product" /> 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="147dp" 
     android:ems="10" 
     android:inputType="number" > 

     <requestFocus /> 
    </EditText> 

</RelativeLayout> 

and the Manifest.xml 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.paypalintegration" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="15" /> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".BuyActivity" 
      android:label="@string/title_activity_pay_pal_integration" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <service 
      android:name="com.paypal.android.sdk.payments.PayPalService" 
      android:exported="false" /> 

     <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" /> 
     <activity android:name="com.paypal.android.sdk.payments.LoginActivity" /> 
     <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" /> 
     <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" /> 
     <activity 
      android:name="io.card.payment.CardIOActivity" 
      android:configChanges="keyboardHidden|orientation" /> 
     <activity android:name="io.card.payment.DataEntryActivity" /> 
    </application> 

</manifest> 

您可以測試我的代碼以logine是

[email protected]

密碼..

personal_sandbox

完整的代碼是在這裏

https://www.dropbox.com/s/f88rean6mpfaibs/PayPalIntegration.zip?m=

+0

請檢查我的代碼是否有問題,然後讓我知道.... – PankajSharma

相關問題